#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> adj[n];
  int i, j;
  int a, b;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
  }
  long long ans = 0;
  for (i = 0; i < n; i++) {
    vector<long long> count(n, 0);
    for (j = 0; j < adj[i].size(); j++) {
      for (int k = 0; k < adj[adj[i][j]].size(); k++) {
        count[adj[adj[i][j]][k]]++;
      }
    }
    for (j = 0; j < n; j++) {
      if (i == j)
        continue;
      else
        ans += ((count[j] * (count[j] - 1)) / 2);
    }
  }
  cout << ans << endl;
  return 0;
}
