#include <bits/stdc++.h>
using namespace std;
vector<int> edge[3123];
int adMatrix[3123][3123], n, m, a, b;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    edge[a].push_back(b);
    adMatrix[a][b] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        long long x = 0;
        int size = edge[i].size();
        for (int k = 0; k < size; k++) {
          if (adMatrix[edge[i][k]][j]) x++;
        }
        ans += (x * (x - 1)) / 2;
      }
    }
  }
  printf("%I64d", ans);
  return 0;
}
