#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void ri(T &i) {
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    ;
  for (i = 0; c >= '0' && c <= '9'; c = getchar())
    i = (i << 3) + (i << 1) + (c - 48);
}
template <typename T>
vector<T> readVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; i++) cin >> res[i];
  return res;
}
const int N = 3005;
bool edge[N][N] = {0};
int main() {
  int n, m;
  ri(n);
  ri(m);
  vector<vector<int> > adj(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    ri(a);
    ri(b);
    a--;
    b--;
    edge[a][b] = true;
    adj[a].push_back(b);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int r = 0;
      for (__typeof((adj[i]).begin()) k = ((adj[i]).begin());
           k != (adj[i]).end(); ++k) {
        int v = *k;
        if (v != i && v != j && edge[v][j]) {
          r++;
        }
      }
      ans += ((r * (r - 1)) / 2);
    }
  }
  cout << ans << "\n";
  return 0;
}
