#include <bits/stdc++.h>
using namespace std;
class Graph {
  int V;

 public:
  Graph(int v);
  vector<vector<int> > adj;
  void addEdge(int v, int u);
};
Graph::Graph(int v) {
  this->V = v;
  adj = vector<vector<int> >(v);
}
void Graph::addEdge(int u, int v) { adj[u].push_back(v); }
long long mod(long long a, long long p = 1e9 + 7) { return (a % p + p) % p; }
void vip(vector<long long> &a) {
  for (long long &i : a) cin >> i;
}
void dfs(Graph &g, int u, map<int, long long> &rhombs, int h, int start) {
  if (h == 2) {
    rhombs[u]++;
    return;
  }
  for (int i : g.adj[u]) {
    if (i != start) dfs(g, i, rhombs, h + 1, start);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  Graph g(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g.addEdge(u, v);
  }
  long long total = 0;
  for (int i = 1; i <= n; i++) {
    map<int, long long> rhombs;
    dfs(g, i, rhombs, 0, i);
    for (auto j : rhombs) total += (((j.second - 1) * (j.second)) / 2);
  }
  cout << total;
  return 0;
}
