#include <bits/stdc++.h>
using namespace std;
const long long nInf = -1000000000;
const long long pInf = 1000000000;
const long long mod = 1000000007;
const int MAXN = 3010;
void getdata();
void preproc();
void solve();
vector<int> g[MAXN];
bool gr[MAXN][MAXN];
int n, m;
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) {
    getdata();
    preproc();
    solve();
  }
  return 0;
}
void getdata() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    gr[x][y] = true;
  }
}
void preproc() {}
void solve() {
  long long res = 0;
  for (int a = 0; a < n; a++) {
    for (int c = 0; c < n; c++) {
      if (a == c) continue;
      int count = 0;
      for (int i = 0; i < (int)g[a].size(); i++) {
        int b = g[a][i];
        if (gr[b][c]) {
          count++;
        }
      }
      res += count * (count - 1) / 2;
    }
  }
  printf("%I64d\n", res);
}
