#include <bits/stdc++.h>
using namespace std;
const int MaxV = 3000 + 10, MaxE = 30000 + 10;
int head[MaxV], nxt[MaxE], to[MaxE], top, n, m, tot[MaxV];
long long ans;
void addedge(int fr, int tt) {
  top++;
  nxt[top] = head[fr];
  to[top] = tt;
  head[fr] = top;
}
void init() {
  int tpa, tpb;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &tpa, &tpb);
    addedge(tpa, tpb);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) tot[j] = 0;
    for (int j = head[i]; j; j = nxt[j])
      for (int k = head[to[j]]; k; k = nxt[k])
        if (to[k] != i) tot[to[k]]++;
    for (int j = 1; j <= n; j++)
      ans += ((long long)tot[j] * (long long)(tot[j] - 1)) / 2ll;
  }
  cout << ans;
  return 0;
}
