#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m;
vector<int> g[200001];
long long d[200001];
void dfs(int v, int p) {
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] == p) continue;
    if (v == p)
      dfs(g[v][i], v);
    else
      d[g[v][i]]++;
  }
}
int main() {
  ios::sync_with_stdio(0);
  while (scanf("%d%d", &n, &m) == 2) {
    long long ans = 0;
    for (int i = 0; i < m; ++i) {
      int a, b;
      scanf("%d%d", &a, &b);
      a--;
      b--;
      g[a].push_back(b);
    }
    for (int i = 0; i < n; ++i) {
      memset(d, 0, sizeof(d));
      dfs(i, i);
      for (int i = 0; i < n; ++i) ans += d[i] * (d[i] - 1) / 2;
    }
    cout << ans << endl;
  }
}
