#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();
	}
}