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