#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test_cases = 1;
  while (test_cases--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n + 1);
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      edges[x - 1].push_back(y - 1);
    }
    vector<vector<int>> count(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < edges[i].size(); j++) {
        for (int k = 0; k < edges[edges[i][j]].size(); k++) {
          int m = edges[edges[i][j]][k];
          count[i][m]++;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j != i) {
          int l = count[i][j];
          l = l * (l - 1) / 2;
          ans = ans + l;
        }
      }
    }
    cout << ans << "\n";
  }
}
