#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const long long MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
long long power(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res = (res % md * a % md) % md;
    a = (a % md * a % md) % md;
    n /= 2;
  }
  res %= md;
  return res;
}
long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); }
class cmp_set {
 public:
  bool operator()(long long a, long long b) { return a > b; }
};
long long n, m;
vector<long long> v[3005];
long long adj[3005][3005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    adj[x][y] = 1;
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (j == i) continue;
      long long tmp = 0;
      for (long long k = 0; k < v[i].size(); k++) {
        if (v[i][k] != i && v[i][k] != j && adj[v[i][k]][j]) tmp++;
      }
      cnt += (tmp * (tmp - 1)) / 2;
    }
  }
  cout << cnt << "\n";
  return 0;
}
