#include <bits/stdc++.h>
using namespace std;
vector<int> g[3010];
bool maps[3010][3010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    maps[u][v] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int res = 0;
      for (int k = 0; k < g[i].size(); k++) {
        int v = g[i][k];
        if (maps[v][j]) res++;
      }
      ans += res * (res - 1) / 2;
    }
  }
  printf("%d\n", ans);
  return 0;
}
