#include <bits/stdc++.h>
using namespace std;
const int maxn = 3050;
const int maxm = 100000;
int cnt = 0;
long long ans = 0;
int head[maxn];
int fa = 0;
int num[maxn];
struct Edge {
  int to, w, next;
} edge[maxm];
void init() {
  cnt = 0;
  for (int i = 0; i < maxn; i++) {
    head[i] = -1;
  }
}
void addedge(int u, int v, int w) {
  edge[cnt].w = w;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  head[u] = cnt++;
}
void dfs(int u, int cntt) {
  if (cntt == 3) {
    if (u != fa) num[u]++;
    return;
  }
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    if (to != u) dfs(to, cntt + 1);
  }
}
long long jc(int k) {
  if (k < 2) return 0;
  long long ab = 1;
  for (int i = k - 1; i <= k; i++) {
    ab *= i;
  }
  return ab / 2;
}
int main() {
  init();
  int n, m;
  memset(num, 0, sizeof(num));
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    addedge(x, y, 1);
  }
  for (int i = 1; i <= n; i++) {
    fa = i;
    dfs(i, 1);
    for (int i = 1; i <= n; i++) {
      ans += jc(num[i]);
    }
    memset(num, 0, sizeof(num));
  }
  printf("%lld", ans);
  return 0;
}
