#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
unordered_map<int, int> m[3001];
vector<vector<int> > v(3001);
void help(int id) {
  unordered_map<int, int>::iterator it;
  for (int i = 0; i < v[id].size(); ++i) {
    for (int j = 0; j < v[v[id][i]].size(); j++) {
      if (v[v[id][i]][j] != id) {
        it = m[id].find(v[v[id][i]][j]);
        if (it != m[id].end())
          m[id][v[v[id][i]][j]]++;
        else
          m[id].insert({v[v[id][i]][j], 1});
      }
    }
  }
}
int choosing(int i) { return i * (i - 1) / 2; }
int main() {
  int n, m1, x, y;
  cin >> n >> m1;
  for (int i = 0; i < m1; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
  }
  for (int i = 1; i < n + 1; i++) {
    help(i);
  }
  int ans = 0;
  for (int id = 1; id < n + 1; id++) {
    for (auto it = m[id].begin(); it != m[id].end(); it++) {
      ans += choosing(it->second);
    }
  }
  cout << ans << "\n";
  ;
  return 0;
}
