#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  vector<vector<long> > edges(n + 1);
  vector<vector<bool> > adj(n + 1, vector<bool>(n + 1, 0));
  for (long p = 0; p < m; p++) {
    long a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    adj[a][b] = 1;
  }
  long long output = 0;
  for (long source = 1; source <= n; source++) {
    for (long target = 1; target <= n; target++) {
      if (source == target) {
        continue;
      }
      long long common = 0;
      for (long p = 0; p < edges[source].size(); p++) {
        if (adj[edges[source][p]][target] > 0) {
          ++common;
        }
      }
      output += common * (common - 1) / 2;
    }
  }
  cout << output << endl;
  return 0;
}
