#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
int g[maxn][maxn];
int n, m, u, v, cnt[maxn][maxn], par;
void dfs(int u, int d) {
  if (d >= 3) return;
  if (d == 2) {
    cnt[par][u]++;
    return;
  }
  for (int i = 1; i <= n; ++i)
    if (g[u][i] && par - i && i - u) {
      dfs(i, d + 1);
    }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &u, &v);
    g[u][v] = 1;
  }
  for (int i = 1; i <= n; i++) {
    par = i;
    dfs(i, 0);
  }
  long long ans = 0ll;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      int tmp = cnt[i][j];
      if (tmp >= 2) {
        ans += (tmp * 1ll * (tmp - 1)) / 2;
      }
    }
  cout << ans << endl;
}
