#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> v[n + 1];
  int graph[n + 1][n + 1];
  memset(graph, 0, sizeof(graph));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a][b] = 1;
    v[a].push_back(b);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      long long path = 0;
      if (i != j)
        for (int k = 0; k < v[i].size(); k++) {
          if (v[i][k] != i && v[i][k] != j && graph[v[i][k]][j]) path++;
        }
      ans += (path * (path - 1)) / 2;
    }
  }
  cout << ans;
  return 0;
}
