#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
const int MAXN = 2.1e5;
const int MAXM = 2.1e5;
int N, M;
int A[MAXM];
int B[MAXM];
vector<int> adj[MAXN];
int par[MAXN][21];
int depth[MAXN];
void dfs_par(int cur, int prv) {
if (prv) {
adj[cur].erase(find(adj[cur].begin(), adj[cur].end(), prv));
}
par[cur][0] = prv;
for (int i = 0; par[cur][i]; i++) {
par[cur][i+1] = par[par[cur][i]][i];
}
depth[cur] = prv ? depth[prv] + 1 : 0;
for (int nxt : adj[cur]) {
dfs_par(nxt, cur);
}
}
int getAnc(int cur, int k) {
assert(k >= 0);
assert(depth[cur] >= k);
while (k > 0) {
int i = __builtin_ctz(k);
cur = par[cur][i];
k -= 1 << i;
}
return cur;
}
int lca(int a, int b) {
if (depth[a] > depth[b]) swap(a, b);
b = getAnc(b, depth[b] - depth[a]);
assert(depth[a] == depth[b]);
if (a == b) return a;
int i = 0;
while (par[a][i] != par[b][i]) {
i++;
}
while (i--) {
if (par[a][i] != par[b][i]) {
a = par[a][i], b = par[b][i];
}
}
return par[a][0];
}
int numPass[MAXN];
void dfs_sub(int cur) {
for (int nxt : adj[cur]) {
dfs_sub(nxt);
numPass[cur] += numPass[nxt];
}
}
int bad[MAXN];
map<pair<int, int>, int> badPairs;
i64 c2(i64 n) {
return n * (n-1) / 2;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> A[i] >> B[i];
}
for (int i = 0; i < N-1; i++) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
dfs_par(1, 0);
for (int i = N-1; i < M; i++) {
int a = A[i], b = B[i];
int c = lca(a, b);
numPass[a] ++;
numPass[b] ++;
numPass[c] -= 2;
}
dfs_sub(1);
i64 ans = 0;
for (int i = N-1; i < M; i++) {
int a = A[i], b = B[i];
int c = lca(a, b);
if (depth[a] > depth[b]) swap(a, b);
assert(a != b);
int pb = getAnc(b, depth[b] - depth[c] - 1);
bad[pb] ++;
ans += numPass[pb];
ans --;
if (a != c) {
int pa = getAnc(a, depth[a] - depth[c] - 1);
bad[pa] ++;
badPairs[minmax(pa, pb)] ++;
ans += numPass[pa];
ans --;
}
}
for (int i = 1; i <= N; i++) {
ans -= c2(bad[i]);
}
for (auto it : badPairs) {
ans -= c2(it.second);
}
cout << ans << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1c2luZyBpNjQgPSBpbnQ2NF90OwoKY29uc3QgaW50IE1BWE4gPSAyLjFlNTsKY29uc3QgaW50IE1BWE0gPSAyLjFlNTsKaW50IE4sIE07CmludCBBW01BWE1dOwppbnQgQltNQVhNXTsKdmVjdG9yPGludD4gYWRqW01BWE5dOwoKaW50IHBhcltNQVhOXVsyMV07CmludCBkZXB0aFtNQVhOXTsKCnZvaWQgZGZzX3BhcihpbnQgY3VyLCBpbnQgcHJ2KSB7CglpZiAocHJ2KSB7CgkJYWRqW2N1cl0uZXJhc2UoZmluZChhZGpbY3VyXS5iZWdpbigpLCBhZGpbY3VyXS5lbmQoKSwgcHJ2KSk7Cgl9CglwYXJbY3VyXVswXSA9IHBydjsKCWZvciAoaW50IGkgPSAwOyBwYXJbY3VyXVtpXTsgaSsrKSB7CgkJcGFyW2N1cl1baSsxXSA9IHBhcltwYXJbY3VyXVtpXV1baV07Cgl9CgoJZGVwdGhbY3VyXSA9IHBydiA/IGRlcHRoW3Bydl0gKyAxIDogMDsKCWZvciAoaW50IG54dCA6IGFkaltjdXJdKSB7CgkJZGZzX3BhcihueHQsIGN1cik7Cgl9Cn0KCmludCBnZXRBbmMoaW50IGN1ciwgaW50IGspIHsKCWFzc2VydChrID49IDApOwoJYXNzZXJ0KGRlcHRoW2N1cl0gPj0gayk7Cgl3aGlsZSAoayA+IDApIHsKCQlpbnQgaSA9IF9fYnVpbHRpbl9jdHooayk7CgkJY3VyID0gcGFyW2N1cl1baV07CgkJay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