#include<bits/stdc++.h>usingnamespace std;#definefifirst#definesesecond#defineIOSstd::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);#defineintlonglongconstint N =2e3+10;constint mod =1e9+7;typedef pair<int,int>PII;
bitset<N>b[N];int n , m;int a[N][N];signedmain(){
IOS
cin >> n >> m;for(int i =1; i <= m ; i ++){int u , v;cin >> u >> v;
b[u][v]= a[u][v]=1;}for(int k =1; k <= n ; k ++){for(int i =1; i <= n ; i ++){if(b[i][k]) b[i]|= b[k];}}int res =0;for(int i =1; i <= n ; i ++){for(int j =1; j <= n ; j ++){if(i != j && b[i][j]&&!a[i][j]) res +=1;}}
cout << res ;return0;}//freopen("文件名.in","r",stdin);//freopen("文件名.out","w",stdout);