#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 1e3;
vector<int> vc[N];
int s, e, x, y;
long long int Ans;
long long int dp[N][N];
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s >> e, vc[s].push_back(e);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < vc[i].size(); j++) {
      x = vc[i][j];
      for (int k = 0; k < vc[x].size(); k++) {
        y = vc[x][k];
        if (i != y) dp[i][y]++;
      }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) Ans += (dp[i][j] * (dp[i][j] - 1)) / 2;
  return cout << Ans << endl, 0;
}
