#include <bits/stdc++.h>
using namespace std;
vector<int> A[3010];
int cnt[3010], parent[3010], visited[3010];
void _do(int n) {
  for (int i = 0; i <= n; i++) {
    visited[i] = false;
    parent[i] = -1;
    cnt[i] = 0;
  }
}
void dfs(int u, int level) {
  int i, v;
  visited[u] = true;
  if (level == 2) {
    cnt[u]++;
    return;
  }
  for (i = 0; i < A[u].size(); i++) {
    v = A[u][i];
    if (parent[u] != v) {
      parent[v] = u;
      dfs(v, level + 1);
    }
  }
}
int main() {
  int i, j, k, n, e;
  scanf("%d%d", &n, &e);
  while (e--) {
    scanf("%d%d", &i, &j);
    A[i].push_back(j);
  }
  int sum = 0;
  for (i = 1; i <= n; i++) {
    _do(n);
    dfs(i, 0);
    for (j = 1; j <= n; j++) {
      if (cnt[j] > 1) sum += (cnt[j] * (cnt[j] - 1)) / 2;
    }
  }
  printf("%d\n", sum);
  return 0;
}
