#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long t = bin_pow(a, b / 2);
    return t * t % 1000000007;
  } else
    return a * bin_pow(a, b - 1) % 1000000007;
}
vector<long long> graph[3000];
long long n, m, a, b, c[3000][3000], k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
  }
  for (int i = 0; i < n; i++) {
    for (auto u : graph[i]) {
      for (auto v : graph[u]) c[i][v]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (c[i][j] >= 2) k += (c[i][j]) * (c[i][j] - 1) / 2;
    }
  }
  cout << k;
  return 0;
}
