#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-6;
const int mod = 1000000007;
const int mx = 3003;
int n, m;
vector<int> adj[mx];
bitset<mx> reachTo[mx], reachFrom[mx];
int vis[mx], start;
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  reachTo[start][x] = 1;
  reachFrom[x][start] = 1;
  for (int i = 0; i < ((int)(adj[x].size())); ++i) dfs(adj[x][i]);
}
int cnt[mx];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    adj[x].push_back(y);
    reachTo[x][y] = 1;
    reachFrom[y][x] = 1;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    memset(cnt, 0, sizeof(cnt));
    for (int idx = 0; idx < ((int)(adj[i].size())); ++idx) {
      int x = adj[i][idx];
      for (int i = 0; i < ((int)(adj[x].size())); ++i) {
        ++cnt[adj[x][i]];
      }
    }
    for (int j = 0; j < (n); ++j)
      if (i != j) ans += cnt[j] * (cnt[j] - 1) / 2;
  }
  printf("%d\n", ans);
  return 0;
}
