#include <bits/stdc++.h>
using namespace std;
long long a[3010][3010];
long long res[3010][3010];
int n, m;
int main() {
  scanf("%d %d", &n, &m);
  memset(a, 0, sizeof a);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[x][y]++;
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++) {
      if (a[i][k] == 0) continue;
      for (int j = 1; j <= n; j++) res[i][j] += a[i][k] * a[k][j];
    }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      ans += (res[i][j] * (res[i][j] - 1)) / 2;
    }
  }
  printf("%d\n", ans);
  return 0;
}
