#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> v[N];
long long nr[N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(nr, 0, sizeof(nr));
    queue<pair<int, int> > q;
    q.push({i, 0});
    while (!q.empty()) {
      int now = q.front().first, d = q.front().second;
      q.pop();
      for (auto it : v[now]) {
        if (it != i) {
          if (d == 1)
            nr[it]++;
          else if (!d)
            q.push({it, 1});
        }
      }
    }
    for (int j = 1; j <= n; j++) ans += (nr[j] * (nr[j] - 1)) / 2;
  }
  cout << ans;
}
