#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
const int MAX = 3005;
vector<int> adj[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, i;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    vector<int> cnt(n + 1, 0);
    for (int x : adj[i]) {
      for (int y : adj[x]) cnt[y]++;
    }
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      ans += (cnt[j] * (cnt[j] - 1)) / 2;
    }
  }
  cout << ans;
}
