#include <bits/stdc++.h>
using namespace std;
const long long size = 3007;
const long long modulo = 1000000007;
const int oo = 1e9;
const double EPS = 1e-12;
const double PI = 3.14159;
vector<int> in[3007], out[3007];
short matr[3007][3007], incom[3007][3007];
short outcom[3007][3007], sub[3007][3007];
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    in[b].push_back(a);
    out[a].push_back(b);
    matr[a][b] = 1;
  }
  for (int v = 1; v <= n; v++) {
    int len = in[v].size();
    for (int i = 0; i < len; i++)
      for (int j = i + 1; j < len; j++) {
        int v1 = in[v][i], v2 = in[v][j];
        if (v1 > v2) swap(v1, v2);
        outcom[v1][v2]++;
      }
  }
  for (int v = 1; v <= n; v++) {
    int len = out[v].size();
    for (int i = 0; i < len; i++)
      for (int j = i + 1; j < len; j++) {
        int v1 = out[v][i], v2 = out[v][j];
        if (v1 > v2) swap(v1, v2);
        incom[v1][v2]++;
        if (matr[v1][v] && matr[v2][v]) ++sub[v1][v2];
      }
  }
  long long ans = 0;
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      ans += int(incom[i][j]) * outcom[i][j] - sub[i][j];
    }
  cout << ans << endl;
  return 0;
}
