#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > dad = vector<vector<int> >(n);
  vector<vector<int> > son = vector<vector<int> >(n);
  for (int i = 0; i < m; i++) {
    int s, d;
    cin >> s >> d;
    son[s - 1].push_back(d - 1);
    dad[d - 1].push_back(s - 1);
  }
  vector<vector<int> > g(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)(dad[i].size()); j++) {
      int d = dad[i][j];
      for (int k = 0; k < (int)(son[i].size()); k++) {
        int s = son[i][k];
        g[d][s]++;
      }
    }
  }
  long long sum = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j) sum += g[i][j] * (g[i][j] - 1) / 2;
  cout << sum << endl;
  return 0;
}
