// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
typedef long long ll;
namespace Fast_Input {
template<class T> inline void read(T& res) {
res = 0;  char ch;  bool sign = 0;
do { ch = getchar();  sign |= ch == '-'; } while(!isdigit(ch));
while(isdigit(ch)) res = (res << 1) + (res << 3) + (ch & 15),ch = getchar();
(sign) && (res = -res);
return;
}
}
int n,m,i,j,k,sta_top,extra,tot,s;
int dfn[maxn],low[maxn],sta[maxn],val[maxn],sz[maxn];
ll ans;
struct Graph {
int head[maxn],nxt[maxn << 1],ver[maxn << 1];   int ecnt;
inline void adde(int u,int v) {
ver[++ecnt] = v;  nxt[ecnt] = head[u];
}
inline void readd(int u,int v) {
}
} gold,gnew;
inline void cmin(int& x,int y) {
if(x > y) x = y;  return;
}
void tarjan(int u) {
dfn[u] = ++tot;  low[u] = ++tot;  sta[++sta_top] = u;  sz[u] = 1;
for(int i = gold.head[u],v;~i;i = gold.nxt[i]) {
v = gold.ver[i];
if(!dfn[v]) {
tarjan(v);  cmin(low[u],low[v]);
if(low[v] >= dfn[u]) {
int t = 0,cnt = 1;  extra++;
do {
t = sta[sta_top--];  cnt++;
sz[extra] += sz[t];
} while(t != v);
val[extra] = cnt;  sz[u] += sz[extra];
}
} else cmin(low[u],dfn[v]);
}
}
void dfs(int u,int fa) {
int x = u <= n;   ans += 2ll * sz[u] * (s - sz[u]) * val[u];
for(int i = gnew.head[u],v;~i;i = gnew.nxt[i]) {
v = gnew.ver[i];  if(v == fa) continue;
ans += 2ll * x * sz[v] * val[u];
x += sz[v];  dfs(v,u);
}
return;
}
int main() {
for(int i = 1;i <= n;i++) val[i] = -1;
for(int i = 1,u,v;i <= m;i++) {