#include <bits/stdc++.h>
using namespace std;
vector<int> vv[3001];
int graf[3001][3001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int f, t;
    cin >> f >> t;
    vv[f].push_back(t);
    graf[f][t] = 1;
  }
  long long ans(0);
  for (int a = 1; a <= n; a++)
    for (int c = 1; c <= n; c++) {
      if (a == c) continue;
      int cnt(0);
      for (int i = 0; i < vv[a].size(); i++) {
        int b = vv[a][i];
        if (graf[b][c]) {
          cnt++;
        }
      }
      ans += 1LL * cnt * (cnt - 1) / 2;
    }
  cout << ans;
}
