#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
vector<int> vec[maxn];
int n, m;
int vis[maxn][maxn];
int vis2[maxn][maxn];
long long ans;
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < maxn; i++) vec[i].clear();
    memset(vis, 0, sizeof(vis));
    memset(vis2, 0, sizeof(vis2));
    int a, b;
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &a, &b);
      vec[a].push_back(b);
      vis[a][b] = 1;
    }
    ans = 0;
    for (int i = 1; i <= n; i++) {
      int b = vec[i].size();
      for (int j = 0; j < b; j++) {
        int u = vec[i][j];
        int num = vec[u].size();
        for (int k = 0; k < num; k++) {
          int v = vec[u][k];
          if (v == u || v == i) continue;
          vis2[i][v]++;
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++)
        if (vis2[i][j] > 1) ans += (long long)vis2[i][j] * (vis2[i][j] - 1) / 2;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
