#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m, a, b, c, ans = 0;
  cin >> n >> m;
  vector<vector<long long>> v(n);
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
  }
  for (long long i = 0; i < n; i++) {
    map<long long, long long> p;
    for (auto j : v[i]) {
      for (auto k : v[j])
        if (j != i && i != k) p[k]++;
    }
    for (auto j : p) {
      c = j.second;
      ans = ans + (c * c - c) / 2;
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}
