#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3010];
long long int mark[3010];
long long int solve(int node) {
  long long int cnt = 0;
  for (int i = 0; i < adj[node].size(); i++) {
    int X = adj[node][i];
    for (int j = 0; j < adj[X].size(); j++) {
      int v = adj[X][j];
      if (v == node) continue;
      if (mark[v]) cnt += mark[v];
      mark[v]++;
    }
  }
  return cnt;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(mark, 0, sizeof(mark));
    ans = ans + solve(i);
  }
  cout << ans << endl;
  return 0;
}
