#include <bits/stdc++.h>
using namespace std;
long long int n, m, ar[3005][3005], sum;
vector<int> v[1000005];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    ar[a][b] = 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      long long int t = 0;
      for (int h = 0; h < v[i].size(); h++) {
        int x = v[i][h];
        if (ar[x][j]) t++;
      }
      sum += t * (t - 1) / 2;
    }
  cout << sum;
}
