#include <bits/stdc++.h>
using namespace std;
vector<int> G[3005];
int n, m;
int vis[3005];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    G[l].push_back(r);
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    int cnt1 = G[i].size();
    memset(vis, 0, sizeof(vis));
    for (int j = 0; j < cnt1; j++) {
      int v = G[i][j];
      int cnt2 = G[v].size();
      for (int k = 0; k < cnt2; k++) {
        int v1 = G[v][k];
        vis[v1]++;
      }
    }
    for (int j = 1; j <= n; j++) {
      if (vis[j] >= 2 && i != j) {
        res += ((vis[j] - 1) * vis[j]) / 2;
      }
    }
  }
  cout << res << endl;
  return 0;
}
