#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> vertex[30005];
  vector<vector<bool> > g(n + 1, vector<bool>(n + 1, false));
  while (m--) {
    long long int a, b;
    cin >> a >> b;
    g[a][b] = true;
    vertex[a].push_back(b);
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++)
    for (long long int j = 1; j <= n; j++) {
      long long int r = 0;
      if (j != i) {
        for (long long int k = 0; k < vertex[i].size(); k++) {
          if (vertex[i][k] != i && vertex[i][k] != j && g[vertex[i][k]][j]) r++;
        }
      }
      ans += r * (r - 1) / 2;
    }
  cout << ans << endl;
  return 0;
}
