#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3010];
bool mat[3010][3010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    mat[u][v] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i != j) {
        long long cnt = 0;
        for (int u : adj[i]) {
          if (mat[u][j] && u != i && u != j) ++cnt;
        }
        ans += (cnt * (cnt - 1)) / 2LL;
      }
    }
  }
  printf("%lld\n", ans);
}
