#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[3001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
  }
  vector<vector<int> > comb(n + 1, vector<int>(n + 1, 0));
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < adj[i].size(); j++) {
      for (int k = 0; k < adj[adj[i][j]].size(); k++) {
        if (adj[adj[i][j]][k] != i) {
          comb[i][adj[adj[i][j]][k]]++;
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < n + 1; j++) {
      ans += (1LL * comb[i][j] * comb[i][j] - comb[i][j]) / 2;
    }
  }
  cout << ans << "\n";
}
