#include <bits/stdc++.h>
using namespace std;
vector<int> G[3005];
int step[3005];
int n, m;
long long ans;
void solve() {
  for (int i = 1; i <= n; i++) {
    memset(step, 0, sizeof(step));
    for (int j = 0; j < G[i].size(); j++) {
      int v = G[i][j];
      for (int k = 0; k < G[v].size(); k++) {
        if (G[v][k] == i) continue;
        step[G[v][k]]++;
      }
    }
    for (int i = 1; i <= n; i++) {
      ans += (step[i] - 1) * step[i] / 2;
    }
  }
}
int main() {
  int from, to;
  while (scanf("%d%d", &n, &m) != EOF) {
    ans = 0;
    for (int i = 0; i <= n; i++) G[i].clear();
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &from, &to);
      G[from].push_back(to);
    }
    solve();
    printf("%I64d\n", ans);
  }
  return 0;
}
