#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return b / gcd(a, b) * a; }
int n, m;
vector<int> v[3001], g[3001];
int x, y;
long long ret;
int calc(int a, int b) {
  int i = 0, j = 0;
  int ret = 0;
  while (i < v[a].size() && j < g[b].size()) {
    if (v[a][i] == g[b][j]) {
      ++ret;
      ++i;
      ++j;
    } else if (v[a][i] > g[b][j])
      ++j;
    else
      ++i;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  while (m--) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    sort(v[i].begin(), v[i].end());
    sort(g[i].begin(), g[i].end());
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      if (i != j) {
        int c = calc(i, j);
        ret += c * (c - 1) / 2;
      }
  }
  cout << ret << endl;
}
