#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int main() {
  long long n, m, i, a, b, A = 0, j, k;
  cin >> n >> m;
  vector<long long> g[n];
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
  }
  for (i = 0; i < n; i++) {
    vector<int> count(n);
    for (j = 0; j < g[i].size(); j++)
      for (k = 0; k < g[g[i][j]].size(); k++) count[g[g[i][j]][k]]++;
    for (j = 0; j < n; j++)
      if (j != i) A += (count[j] * (count[j] - 1)) / 2;
  }
  cout << A << endl;
}
