#include <bits/stdc++.h>
using namespace std;
int ver, edg, n;
vector<int> G[3005];
vector<int> ans;
int timesvis[3005] = {0};
int vis;
void dfs(int vertex, int level) {
  int i;
  if (level == 0) {
    for (i = 0; i < G[vertex].size(); i++) {
      dfs(G[vertex][i], level + 1);
    }
  } else if (level == 1) {
    for (i = 0; i < G[vertex].size(); i++) {
      if (G[vertex][i] != vis) dfs(G[vertex][i], level + 1);
    }
  } else {
    timesvis[vertex]++;
    if (timesvis[vertex] == 2) ans.push_back(vertex);
  }
}
int main() {
  int i, j, fl, test, x, y;
  long long total = 0;
  scanf("%d%d", &ver, &edg);
  for (i = 0; i < edg; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
  }
  for (i = 1; i <= ver; i++) {
    ans.clear();
    vis = i;
    memset(timesvis, 0, sizeof(timesvis));
    dfs(i, 0);
    for (j = 0; j < ans.size(); j++) {
      total += (timesvis[ans[j]] * (timesvis[ans[j]] - 1)) / 2;
    }
  }
  printf("%lld\n", total);
  return 0;
}
