#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897;
const int mod = 1000000007;
const int M = 100005;
int INF = INT_MAX;
vector<int> gL[3001];
int gM[3001][3001];
int solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gL[u].push_back(v);
    gM[u][v] = 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        long long x = 0;
        for (auto k : gL[i]) {
          if (gM[k][j]) x++;
        }
        if (x > 0) ans += x * (x - 1) / 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  cin.sync_with_stdio(false);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
