#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > graph;
long long cnts[3005][3005];
void dfs(long long node, long long parent, long long dis) {
  if (node == parent) return;
  if (dis == 2) {
    cnts[node][parent] += 1;
    return;
  }
  for (int i = 0; i < graph[node].size(); i++) {
    dfs(graph[node][i], parent, dis + 1);
  }
  return;
}
int main() {
  long long n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  graph.resize(n + 2);
  graph.clear();
  long long x, y;
  for (int i = 0; i < m; i++) {
    scanf("%lld", &x);
    scanf("%lld", &y);
    graph[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      dfs(graph[i][j], i, 1);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (cnts[i][j] >= 2) {
        ans += (cnts[i][j] * (cnts[i][j] - 1)) / 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
