#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int minn = 1e5 + 9;
const int N = 5e3 + 123;
const int NN = 5e5 + 123;
const int PRI = 555557;
const int pri = 997;
int tests = 1;
int n, m, k, cnt[N];
long long ans;
vector<int> g[N];
void dfs(int v, int lvl = 0) {
  if (lvl == 2) {
    cnt[v]++;
    return;
  }
  for (auto to : g[v]) {
    dfs(to, lvl + 1);
  }
}
inline void Solve() {
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cnt[j] = 0;
    dfs(i);
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        ans += 1ll * cnt[j] * (cnt[j] - 1) / 2;
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  while (tests--) {
    Solve();
  }
}
