#include <bits/stdc++.h>
using namespace std;
vector<int> edge[3009];
int graph[3009][3009];
int main() {
  int n, m, i, j, ans = 0, a, b, c;
  cin >> n >> m;
  memset(graph, 0, sizeof(graph));
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    edge[a].push_back(b);
    graph[a][b] = 1;
  }
  for (a = 1; a <= n; a++) {
    for (c = 1; c <= n; c++) {
      if (a != c) {
        int r = 0;
        for (b = 0; b < edge[a].size(); b++) {
          int x = edge[a][b];
          if (x != a && x != c && graph[x][c]) r++;
        }
        ans += (r * (r - 1) / 2);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
