#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int mat[N][N];
vector<int> adj[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    mat[u][v] = 1;
    adj[u].push_back(v);
  }
  long long ans = 0;
  for (int u = 0; u < n; ++u) {
    for (int v = 0; v < n; ++v) {
      if (u == v) continue;
      long long cnt = 0;
      for (int w : adj[u]) {
        if (mat[w][v]) cnt++;
      }
      ans += cnt * (cnt - 1) / 2;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
