#include <bits/stdc++.h>
using namespace std;
long n, m;
vector<long> g[3000];
bool he[3000][3000];
long long ans;
void add_edge(long a, long b) {
  g[a].push_back(b);
  he[a][b] = true;
}
void input_data() {
  cin >> n >> m;
  long a, b;
  for (long i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    add_edge(a, b);
  }
}
void process_data() {
  ans = 0;
  for (long a = 0; a < n; a++) {
    for (long c = 0; c < n; c++) {
      long r = 0;
      if (c == a) continue;
      for (size_t i = 0; i < g[a].size(); i++) {
        long b = g[a][i];
        if (he[b][c]) r++;
      }
      ans += r * (r - 1) / 2;
    }
  }
}
void output_data() { cout << ans; }
int main() {
  input_data();
  process_data();
  output_data();
  return 0;
}
