#include <bits/stdc++.h>
int n, m;
typedef struct {
  int con[3010];
  int nc;
} sect;
sect arr[3010];
int ans;
bool can[3010][3010] = {{false}};
int main() {
  ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int f, t;
    scanf("%d%d", &f, &t);
    arr[f - 1].con[arr[f - 1].nc++] = t - 1;
    can[f - 1][t - 1] = true;
  }
  int count, i, j, k;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      if (i == j) continue;
      count = 0;
      for (k = 0; k < arr[i].nc; ++k) {
        if (can[arr[i].con[k]][j]) count++;
      }
      ans += count * (count - 1) / 2;
    }
  }
  printf("%d\n", ans);
}
