#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > city[2];
bool found[3001][3001];
bool used[3001][2];
int main() {
  int n, m;
  cin >> n >> m;
  city[0].resize(n + 1);
  city[1].resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    city[0][a].push_back(b);
    city[1][b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (city[0][i].size() == 0) continue;
    for (int j = 0; j < 3001; j++) {
      used[0][j] = false;
      used[1][j] = false;
    }
    for (int j = 0; j < city[0][i].size(); j++) {
      used[0][city[0][i][j]] = true;
    }
    for (int j = 0; j <= n; j++) {
      int ans1 = 0;
      for (int k = 0; k < city[1][j].size(); k++) {
        ans1 += used[0][city[1][j][k]] && j != i;
      }
      ans += ans1 * (ans1 - 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}
