#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > matrix;
vector<vector<int> > graph;
int main(void) {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  matrix.clear();
  matrix.resize(n + 1, vector<bool>(m + 1, false));
  graph.clear();
  graph.resize(n + 1);
  while (m--) {
    scanf("%d%d", &a, &b);
    matrix[a - 1][b - 1] = true;
    graph[a - 1].push_back(b - 1);
  }
  int res = 0, ctr;
  for (int a = 0; a < n; a++) {
    for (int d = 0; d < n; d++) {
      if (a != d) {
        ctr = 0;
        for (auto it = graph[a].begin(); it != graph[a].end(); it++) {
          if (matrix[*it][d]) ctr++;
        }
        res += (ctr * (ctr - 1)) / 2;
      }
    }
  }
  printf("%d\n", res);
}
