#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (size_t i = 0; i < v.size(); ++i) in >> v[i];
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> const &v) {
  for (size_t i = 0; i < v.size(); ++i) out << v[i] << " ";
  return out;
}
void solution();
int main() {
  solution();
  return EXIT_SUCCESS;
}
vector<int> g[3002];
long long u[3002];
int d[3002];
void dfs(int v, int depth = 0) {
  d[v] = depth;
  if (depth == 2) {
    ++u[v];
    return;
  }
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs(to, depth + 1);
  }
}
void solution() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
  }
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      u[j] = 0;
      d[j] = -1;
    }
    dfs(i);
    for (int j = 0; j < n; ++j)
      if (i != j && u[j]) {
        res += (u[j] * (u[j] - 1)) / 2;
      }
  }
  cout << res << endl;
}
