#include <bits/stdc++.h>
using namespace std;
long long int mult(long long int a, long long int b) {
  return ((a * b) % 1000000007);
}
long long int pow_m(long long int a, long long int p) {
  if (p == 0) {
    return 1;
  } else if (p == 1) {
    return a;
  }
  long long int temp = pow_m(a, p / 2);
  if (p % 2 == 0) {
    return mult(temp, temp);
  } else {
    return mult(mult(temp, temp), a);
  }
}
long long int inv(long long int a) {
  if (a == 0) {
    return 0;
  }
  return pow_m(a, 1000000007 - 2);
}
long long int nChooseK(long long int n, long long int k) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  for (int i = 0; i < k; ++i) {
    answer = mult(answer, n - i);
  }
  for (int i = 2; i <= k; ++i) {
    answer = mult(answer, inv(i));
  }
  return answer;
}
long long int nChooseK(long long int n, long long int k,
                       vector<long long int>& pre_mult,
                       vector<long long int>& pre_div) {
  if (k == 0) {
    return 1;
  }
  long long int answer = 1;
  answer = mult(answer, pre_mult[n]);
  answer = mult(answer, pre_div[n - k]);
  answer = mult(answer, pre_div[k]);
  return answer;
}
vector<long long int> coordinate_compression(vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  vector<long long int> answer = input;
  long long int index = 0;
  while (index < b.size()) {
    answer[index] = mp[answer[index]];
  }
  return answer;
}
map<long long int, long long int> get_coordinate_compression_map(
    vector<long long int>& input) {
  vector<long long int> b = input;
  sort(b.begin(), b.end());
  map<long long int, long long int> mp;
  for (long long int i = 0; i < b.size(); ++i) {
    if (mp.find(b[i]) == mp.end()) {
      mp[b[i]] = i;
    }
  }
  return mp;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> neighbors(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    neighbors[a - 1].push_back(b - 1);
  }
  int64_t answer = 0;
  for (int i = 0; i < n; ++i) {
    vector<int64_t> total_paths(n, 0);
    for (int j = 0; j < neighbors[i].size(); ++j) {
      for (int k = 0; k < neighbors[neighbors[i][j]].size(); ++k) {
        if (neighbors[neighbors[i][j]][k] != i) {
          total_paths[neighbors[neighbors[i][j]][k]]++;
        }
      }
    }
    for (int j = 0; j < n; ++j) {
      if (total_paths[j] >= 2) {
        answer += total_paths[j] * (total_paths[j] - 1) / 2;
      }
    }
  }
  cout << answer << "\n";
  return 0;
}
