#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long n, m;
vector<set<long long>> adj;
long long dfs(long long u, long long v) {
  map<long long, long long> mp;
  mp.clear();
  for (auto k : adj[u]) {
    for (auto j : adj[k]) {
      if (j == u) continue;
      mp[j]++;
    }
  }
  long long final = 0;
  for (auto k : mp) {
    if (u == 0)
      if (false) cerr << k.second << " " << k.first << '\n';
    final += (k.second - 1) * (k.second) / 2;
  }
  if (false) cerr << final << " ";
  return final;
}
void solve() {
  cin >> n >> m;
  adj.resize(n);
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].insert(y);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += dfs(i, -1);
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL),
      cout << setprecision(14);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
