#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1LL << 60) - 1;
const long long int MAX = 1000000001;
const long long int mod = 1000000007;
std::vector<long long int> edge[300001];
long long int val[3001] = {0};
long long int ans = 0;
long long int fast_exp(long long int base, long long int exp, long long int m) {
  long long int res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % m;
    }
    base = (base * base) % m;
    exp /= 2;
  }
  return res % m;
}
long long int cnt(long long int q) {
  long long int temp = q * (q - 1) / 2;
  return temp;
}
void dfs(long long int v, long long int count, long long int par) {
  if (count == 2) {
    val[v]++;
    return;
  }
  count++;
  for (long long int i = 0; i < edge[v].size(); i++) {
    if (par != edge[v][i]) dfs(edge[v][i], count, v);
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, a, b;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    cin >> a >> b;
    edge[a].push_back(b);
  }
  for (long long int i = 1; i <= n; i++) {
    dfs(i, 0, i);
    for (long long int j = 1; j <= n; j++)
      if (val[j] > 0) ans += cnt(val[j]);
    for (long long int j = 1; j <= n; j++) val[j] = 0;
  }
  cout << ans << '\n';
  return 0;
}
