#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m;
int main() {
  std ::ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<vector<bool> > mask(n + 1, vector<bool>(n + 1, false));
  vector<vector<int> > adj(n + 1, vector<int>());
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    mask[x][y] = true;
  }
  long long ans = 0;
  for (int a = 1; a <= n; ++a) {
    for (int c = 1; c <= n; ++c) {
      if (a != c) {
        int edge = 0;
        for (int childs : adj[a]) {
          if (mask[childs][c]) {
            edge++;
          }
        }
        ans += (1LL * edge * (edge - 1LL)) / 2LL;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
