#include <bits/stdc++.h>
using namespace std;
vector<int> a[30010];
long long ans, k;
int n, m, x[30010], y[30010], i, j, xx, yy;
map<pair<int, int>, long long> Mp;
map<pair<int, int>, long long>::iterator it;
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x[i], &y[i]);
    a[x[i]].push_back(y[i]);
  }
  for (i = 1; i <= m; i++) {
    xx = x[i];
    yy = y[i];
    for (j = 0; j < a[yy].size(); j++)
      if (xx != a[yy][j]) {
        Mp[make_pair(xx, a[yy][j])]++;
      }
  }
  for (it = Mp.begin(); it != Mp.end(); it++) {
    k = (*it).second;
    ans += k * (k - 1);
  }
  printf("%I64d", ans / 2);
  return 0;
}
