#include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout< edge; map num; map cnt; ll dfs(ll s){ if(num[s]!=-1){ if(!cnt[s])cnt[s]=true; else return num[s]; } if(!cnt[s])num[s]=s; for(auto& e:edge[s])num[s]=max(num[s],dfs(e)); cnt[s]=true; return num[s]; } int main(){ ll n;int m;cin>>n>>m; vll b(m);ll c; rep(i,m){ cin>>b[i]>>c; edge[b[i]].push_back(c); num[b[i]]=-1;num[c]=-1; cnt[b[i]]=false;cnt[c]=false; } ll ans=n*(n+1)/2; rep(i,m)ans+=dfs(b[i])-b[i]; cout<