#include <bits/stdc++.h>
using namespace std;
int visited[3010][3010];
vector<int> v[100009];
long long ans = 0;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    visited[a][b] = 1;
    v[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        long long r = 0;
        for (int k = 0; k < v[i].size(); k++) {
          int x = v[i][k];
          if (x != i && x != j && visited[x][j]) r++;
        }
        ans = ans + (r * (r - 1) / 2);
      }
    }
  }
  cout << ans << endl;
}
