#include <bits/stdc++.h>
using namespace std;
inline void scan(int &a) { scanf("%d", &a); }
inline void scan(int &a, int &b) { scanf("%d %d", &a, &b); }
inline void scan(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
inline void scan(long long &a) { scanf("%lld", &a); }
inline void scan(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
inline void scan(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
inline void print() { printf("\n"); }
inline void print(int a) { printf("%d ", a); }
inline void print(int a, int b) { printf("%d %d ", a, b); }
inline void print(int a, int b, int c) { printf("%d %d %d ", a, b, c); }
inline void print(long long a) { printf("%lld ", a); }
inline void print(long long a, long long b) { printf("%lld %lld ", a, b); }
inline void print(long long a, long long b, long long c) {
  printf("%lld %lld %lld ", a, b, c);
}
const int MAXN = 3010;
vector<int> edge[MAXN];
int cnt[MAXN];
int main() {
  int n, m;
  scan(n, m);
  int a, b;
  for (int i = 1; i <= m; i++) {
    scan(a, b);
    edge[a].push_back(b);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cnt[j] = 0;
    for (int j = 0; j < edge[i].size(); j++) {
      int node = edge[i][j];
      for (int k = 0; k < edge[node].size(); k++)
        if (edge[node][k] != i) cnt[edge[node][k]]++;
    }
    for (int j = 1; j <= n; j++) ans += (1LL * cnt[j] * (cnt[j] - 1)) / 2;
  }
  print(ans);
  print();
  return 0;
}
