#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int M = 30005;
int n, m, ans, tot = 1, f[N], ver[M], nex[M], head[N];
void add(int x, int y) { nex[tot] = head[x], ver[tot] = y, head[x] = tot++; }
int main() {
  int i = 0, j, k, x, y;
  scanf("%d%d", &n, &m);
  for (; i++ < m;) scanf("%d%d", &x, &y), add(x, y);
  for (x = 1; x <= n; x++) {
    for (j = head[x]; j; j = nex[j])
      for (y = head[ver[j]]; y; y = nex[y]) f[ver[y]]++;
    for (j = 1; j <= n; f[j++] = 0)
      if (j ^ x) ans += f[j] * (f[j] - 1) >> 1;
  }
  printf("%d", ans);
}
