#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int __gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
vector<vector<int> > adj;
vector<int> cont;
int main() {
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  adj = vector<vector<int> >(n + 1, vector<int>());
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
  }
  long long res = 0, temp;
  for (int i = 1; i <= n; i++) {
    queue<int> qu;
    cont = vector<int>(n + 1, 0);
    for (int v : adj[i]) {
      qu.push(v);
    }
    while (!qu.empty()) {
      u = qu.front();
      qu.pop();
      for (int nxt : adj[u]) {
        if (nxt == i) continue;
        cont[nxt]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (j == i || cont[j] <= 1) continue;
      temp = cont[j];
      temp *= (temp - 1);
      temp /= 2LL;
      res += temp;
    }
  }
  printf("%lld\n", res);
  return 0;
}
