#include <bits/stdc++.h>
using namespace std;
int ak[3008] = {0}, ans = 0, st_root = 0;
vector<int> adj[3005];
void dfs(int root, int level) {
  int u = root;
  int sz = adj[u].size();
  for (int i = 0; i < sz; i++) {
    int v = adj[u][i];
    if (level == 1) {
      dfs(v, level + 1);
    }
    if (level == 2) {
      if (v != st_root) ak[v]++;
    }
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    memset(ak, 0, sizeof(ak));
    st_root = i;
    dfs(i, 1);
    for (int j = 1; j <= 3005; j++) {
      if (ak[j] >= 2) {
        int temp = ak[j] * (ak[j] - 1);
        temp = temp / 2;
        ans = ans + temp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
