#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const double PI = acos(-1);
long long gcd() { return 0ll; }
template <typename T, typename... Args>
T gcd(T a, Args... args) {
  return __gcd(a, (__typeof(a))gcd(args...));
}
vector<int> G[3010];
bool vis[3010];
long long res[3010];
long long ans = 0;
void dfs(int u, int d) {
  if (vis[u]) return;
  if (d == 0) {
    ans -= (res[u] * (res[u] - 1)) / 2;
    res[u]++;
    ans += (res[u] * (res[u] - 1)) / 2;
    return;
  }
  vis[u] = 1;
  for (auto it : G[u]) dfs(it, d - 1);
  vis[u] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    int n, m, x, y;
    cin >> n >> m;
    for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
         i += 1 - 2 * ((0) > (m))) {
      cin >> x >> y;
      x--;
      y--;
      G[x].emplace_back(y);
    }
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      for (__typeof(n) j = (0) - ((0) > (n)); j != (n) - ((0) > (n));
           j += 1 - 2 * ((0) > (n)))
        res[j] = 0, vis[j] = 0;
      dfs(i, 2);
    }
    cout << ans << "\n";
  }
  return 0;
}
