#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printArray(T arr, int l) {
  for (int i = 0; i < l; i++) cout << arr[i] << " ";
  cout << endl;
}
vector<vector<int> > graph(3005);
int n, m;
int parentCount[3005];
void dfs(int curNode, int depth) {
  if (depth == 0) {
    parentCount[curNode]++;
  } else {
    int sz = graph[curNode].size();
    for (int i = 0; i < sz; i++) {
      dfs(graph[curNode][i], depth - 1);
    }
  }
  return;
}
int main(void) {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    memset(parentCount, 0, sizeof parentCount);
    dfs(i, 2);
    for (int j = 0; j < n; j++) {
      if (j != i) {
        long long int cur = parentCount[j];
        ans += (cur * (cur - 1)) / 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
