#include <bits/stdc++.h>
using namespace std;
const int maxn = 4096;
const long long INF = 1e15 + 7;
int n, m;
vector<int> g[maxn];
int d[maxn];
int dfs(int x, int depth, int root) {
  if (depth == 2) return d[x]++;
  int ans = 0;
  for (int i = int(0); i <= int(g[x].size() - 1); ++i)
    if (g[x][i] != root) ans += dfs(g[x][i], depth + 1, root);
  return ans;
}
int calc(int x) {
  int ans = 0;
  for (int i = int(1); i <= int(n); ++i) d[i] = 0;
  return dfs(x, 0, x);
}
long long ans;
int a, b;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = int(1); i <= int(m); ++i) {
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
  }
  for (int i = int(1); i <= int(n); ++i) ans += calc(i);
  printf("%I64d", ans);
  return 0;
}
