#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int powmod(int a, int b) {
  int tmp = 1;
  a %= (10007);
  for (; b; b >>= 1) {
    if (b & 1) tmp = (long long)tmp * a % (10007);
    a = (long long)a * a % (10007);
  }
  return tmp;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
template <class T>
inline void add(int &x, T y) {
  for (x += y; x >= (10007); x -= (10007))
    ;
}
int n, m, x, y, ans, in[20011];
vector<int> g[20011];
void dfs(int t, int rt, int flag) {
  if (!flag) {
    if (t != rt) in[t]++;
    return;
  }
  for (int i = 0; i < (int)((int)g[t].size()); i++) dfs(g[t][i], rt, flag - 1);
}
int main() {
  R(n);
  R(m);
  for (int i = 0; i < (int)m; i++) R(x), R(y), x--, y--, g[x].push_back(y);
  for (int i = 0; i < (int)n; i++) {
    memset(in, 0, sizeof(in));
    dfs(i, i, 2);
    for (int j = 0; j < (int)n; j++)
      if (in[j] >= 2) ans += in[j] * (in[j] - 1) / 2;
  }
  printf("%d\n", ans);
  return 0;
}
