#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
bool G[maxn][maxn];
vector<int> nxt[maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a][b] = true;
    nxt[a].push_back(b);
  }
  int ans = 0;
  for (int a = 1; a <= n; ++a)
    for (int c = 1; c <= n; ++c) {
      if (a != c) {
        int r = 0;
        for (int b = 0; b < nxt[a].size(); ++b) {
          if (nxt[a][b] != a && nxt[a][b] != c && G[nxt[a][b]][c]) r++;
        }
        ans += r * (r - 1) / 2;
      }
    }
  printf("%d\n", ans);
  return 0;
}
