#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
const int INF = 0x3f3f3f3f;
const int mod = 10000007;
const double eps = 1e-9;
int __ = 1, kase = 0;
int n, m, d[maxn][maxn];
vector<int> G[maxn];
void init() {}
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      int u = G[i][j];
      for (int k = 0; k < G[u].size(); k++) {
        int r = G[u][k];
        d[i][r]++;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        if (d[i][j] > 1) {
          ans += d[i][j] * (d[i][j] - 1) / 2;
        }
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  while (__--) {
    init();
    read();
    solve();
  }
  return 0;
}
