#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
const int N = 2e3 + 5;
vector<int> in[N], out[N];
set<pair<int, int>> s;
void Solve(){
int n, m;
cin>>n>>m;
for(int i = 0; i < m; i++){
int u, v;
cin>>u>>v;
in[v].push_back(u);
out[u].push_back(v);
s.insert({u, v});
}
long long res = 0;
for(int i = 1; i <= n; i++){
for(auto x: in[i]){
for(auto y: out[i]){
if(x == y) continue;
if(s.find({x, y}) == s.end()){
//cout<<x<<" "<<y<<nl;
s.insert({x, y});
res++;
in[y].push_back(x);
out[x].push_back(y);
}
}
}
}
cout<<res<<nl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int T = 1;
//cin>>T;
while(T--){
Solve();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIG5sICdcbicKCmNvbnN0IGludCBOID0gMmUzICsgNTsKCnZlY3RvcjxpbnQ+IGluW05dLCBvdXRbTl07CgpzZXQ8cGFpcjxpbnQsIGludD4+IHM7Cgp2b2lkIFNvbHZlKCl7CglpbnQgbiwgbTsKCWNpbj4+bj4+bTsKCWZvcihpbnQgaSA9IDA7IGkgPCBtOyBpKyspewoJCWludCB1LCB2OwoJCWNpbj4+dT4+djsKCQlpblt2XS5wdXNoX2JhY2sodSk7CgkJb3V0W3VdLnB1c2hfYmFjayh2KTsKCQlzLmluc2VydCh7dSwgdn0pOwoJfQoJbG9uZyBsb25nIHJlcyA9IDA7Cglmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CgkJZm9yKGF1dG8geDogaW5baV0pewoJCQlmb3IoYXV0byB5OiBvdXRbaV0pewoJCQkJaWYoeCA9PSB5KSBjb250aW51ZTsKCQkJCWlmKHMuZmluZCh7eCwgeX0pID09IHMuZW5kKCkpewoJCQkJCS8vY291dDw8eDw8IiAiPDx5PDxubDsKCQkJCQlzLmluc2VydCh7eCwgeX0pOwoJCQkJCXJlcysrOwoJCQkJCWluW3ldLnB1c2hfYmFjayh4KTsKCQkJCQlvdXRbeF0ucHVzaF9iYWNrKHkpOwoJCQkJfQoJCQl9CgkJfQoJfQoJY291dDw8cmVzPDxubDsKCn0KaW50IG1haW4oKXsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7CglpbnQgVCA9IDE7CgkvL2Npbj4+VDsKCXdoaWxlKFQtLSl7CgkJU29sdmUoKTsKCX0KfQ==