#include <bits/stdc++.h>
using namespace std;
vector<int> vec[3003];
bool mat[3333][3333];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    mat[a][b] = 1;
    vec[a].push_back(b);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int now = 0;
      if (i != j) {
        for (int b = 0; b < vec[i].size(); b++) {
          if (vec[i][b] != j && mat[vec[i][b]][j]) {
            now++;
          }
        }
      }
      res += (now * (now - 1)) / 2;
    }
  }
  cout << res << endl;
  return 0;
}
