#include <bits/stdc++.h>
using namespace std;
long long int solve(long long int mid) { return (mid * (mid - 1)) / 2; }
int n, m;
vector<int> v1[3100];
bool vis[3100][3100];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i += 1) {
    int u, v;
    cin >> u >> v;
    v1[u].push_back(v);
    vis[u][v] = true;
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i += 1) {
    for (int j = 1; j <= n; j += 1) {
      if (i == j) continue;
      int cnt = 0;
      for (auto itr : v1[i]) {
        if (itr == i) continue;
        if (itr == j) continue;
        if (vis[itr][j]) cnt += 1;
      }
      ans += solve(cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
