#include <bits/stdc++.h>
using namespace std;
long long int a[3005][3005];
vector<long long int> v[3005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  ;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    ;
    v[x].push_back(y);
    a[x][y] = 1;
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        long long int res = 0;
        for (int k = 0; k < v[i].size(); k++) {
          if (v[i][k] != i && v[i][k] != j && a[v[i][k]][j] == 1) {
            res++;
          }
        }
        ans = ans + (res * (res - 1)) / 2;
      }
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
