#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
vector<int> g[maxn];
int cnt[maxn];
void dfs(int x, int f, int dep) {
  if (dep == 2) {
    cnt[x]++;
    return;
  }
  int z = g[x].size();
  for (int i = 0; i < z; i++) {
    int t = g[x][i];
    if (t == f) continue;
    dfs(t, x, dep + 1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(cnt, 0, sizeof(cnt));
    dfs(i, 0, 0);
    for (int i = 1; i <= n; i++) {
      if (cnt[i] > 1) {
        ans += ((cnt[i] - 1) * cnt[i] / 2);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
