#include <bits/stdc++.h>
using namespace std;
int g[3002][3002];
int m, n;
vector<int> v[3002];
int main() {
  scanf("%d%d", &n, &m);
  for (int j = 0; j < m; j++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    g[x][y] = 1;
    v[x].push_back(y);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int cnt = 0;
      int len = v[i].size();
      for (int l = 0; l < len; l++) {
        int k = v[i][l];
        if (k == i || k == j) continue;
        if (g[i][k] == 1 && g[k][j] == 1) cnt++;
      }
      ans += (long long)cnt * (cnt - 1) / 2;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
