#include <bits/stdc++.h>
using namespace std;
const int MAX = 3010;
vector<int> graph[MAX];
int seen[MAX];
void dfs(int node, int d) {
  if (d == 2) seen[node]++;
  if (d < 2)
    for (auto& target : (graph[node])) dfs(target, d + 1);
}
int main() {
  int n;
  scanf("%d", &(n));
  ;
  int m;
  scanf("%d", &(m));
  ;
  for (int(i) = (0); (i) < (m); (i)++) {
    int a;
    scanf("%d", &(a));
    ;
    int b;
    scanf("%d", &(b));
    ;
    if (a != b) graph[a].push_back(b);
  }
  long long ans = 0;
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    memset(seen, 0, sizeof(seen));
    dfs(i, 0);
    for (int(j) = (1); (j) < (n + 1); (j)++)
      if (i != j) {
        ans += (1LL * seen[j] * (seen[j] - 1)) / 2;
      }
  }
  cout << (ans) << "\n";
  ;
}
