#include <bits/stdc++.h>
using namespace std;
char q[3001][3001];
int main() {
  int n, m, ta, tb;
  long long ans = 0;
  scanf("%d%d", &n, &m);
  vector<int> as[30001];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &ta, &tb);
    as[ta].push_back(tb);
    q[ta][tb] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      long long c = 0;
      if (i == j) continue;
      for (long long k = 0; k < (int)as[i].size(); k++) {
        if (as[i][k] != i && as[i][k] != j && q[as[i][k]][j] == 1) c++;
      }
      ans += (c * (c - 1)) / 2;
    }
  }
  printf("%lld\n", ans);
}
