#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dc[] = {0, 1, 0, -1, 1, 1, -1, -1};
int n, m;
vector<vector<int> > adjlist;
vector<int> dist;
vector<int> visited;
void dfs(int node, int sisa) {
  if (sisa == 0) {
    return;
  }
  for (int i = (0); i <= ((int)adjlist[node].size() - 1); i += (1)) {
    int haha = adjlist[node][i];
    if (visited[haha] == 0) {
      visited[haha] = 1;
      dist[haha]++;
      dfs(haha, sisa - 1);
    } else {
      if (sisa == 1) {
        dist[haha]++;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> n >> m) {
    adjlist.assign(n, vector<int>());
    for (int i = (0); i <= (m - 1); i += (1)) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      adjlist[x].push_back(y);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      dist.assign(n, 0);
      visited.assign(n, 0);
      visited[i] = 1;
      queue<pair<int, int> > q;
      q.push(pair<int, int>(0, i));
      while (!q.empty()) {
        pair<int, int> u = q.front();
        q.pop();
        int banyak = u.first, node = u.second;
        if (banyak == 2) continue;
        for (int j = (0); j <= ((int)adjlist[node].size() - 1); j += (1)) {
          if (visited[adjlist[node][j]] == 0) {
            visited[adjlist[node][j]] = 1;
            q.push(pair<int, int>(banyak + 1, adjlist[node][j]));
          }
          if (banyak == 1) {
            dist[adjlist[node][j]]++;
          }
        }
      }
      for (int j = (0); j <= (n - 1); j += (1)) {
        if (i == j) continue;
        ans += (long long)dist[j] * ((long long)dist[j] - 1) / 2;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
