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