#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print2dvector(vector<vector<T> > v) {
  cout << "A 2d vector:" << endl;
  int a = v.size();
  int b = v[0].size();
  if (a <= 15 && b <= 15) {
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
  }
  if (a > 15 && b > 15) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
    for (int i = 0; i < 15; i++) {
      cout << setw(4) << '.';
    }
    cout << endl;
    for (int i = a - 3; i < a; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
  }
  if (a > 15) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
    for (int i = 0; i < b; i++) {
      cout << setw(4) << '.';
    }
    cout << endl;
    for (int i = a - 3; i < a; i++) {
      for (int j = 0; j < b; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << endl;
    }
  }
  if (b > 15) {
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < 9; j++) {
        cout << setw(4) << v[i][j];
      }
      cout << "   "
           << ".   .   ." << setw(4) << v[i][b - 3] << setw(4) << v[i][b - 2]
           << setw(4) << v[i][b - 1] << endl;
    }
  }
}
template <typename T>
void printvector(vector<T> v) {
  cout << "A 1d vector:" << endl;
  int a = v.size();
  if (a <= 15) {
    for (int i = 0; i < a; i++) {
      cout << setw(4) << v[i];
    }
  } else {
    for (int i = 0; i < 9; i++) {
      cout << setw(4) << v[i];
    }
    cout << "   "
         << ".   .   ." << setw(4) << v[a - 3] << setw(4) << v[a - 2] << setw(4)
         << v[a - 1];
  }
  cout << endl;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<bool> > connectivity_matrix(n, vector<bool>(n, false));
  vector<vector<int> > adj_list(n);
  int a, b;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    connectivity_matrix[a][b] = true;
    adj_list[a].push_back(b);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i) {
        int amount = 0;
        for (int k = 0; k < adj_list[i].size(); k++) {
          if (connectivity_matrix[adj_list[i][k]][j]) {
            amount++;
          }
        }
        ans += (amount * (amount - 1)) / 2;
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
