public static void main(String... args) throws IOException {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer>[] edgs = new ArrayList[n];
        ArrayList<Integer>[] redgs = new ArrayList[n];

        for (int i = 0; i < n; i++) {
            edgs[i] = new ArrayList<>();
            redgs[i] = new ArrayList<>();
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            edgs[a].add(b);
            redgs[b].add(a);
        }

        boolean[] visited = new boolean[n];
        int out = 0;
        for (int i = 0; i < n; i++) {
            clean(visited);
            for (int v : edgs[i]) {
                visited[v] = true;
            }

            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int count = 0;
                    for (int v : redgs[j]) {
                        if (visited[v]) {
                            count++;
                        }
                    }
                    if (count >= 2) {
                        out += (count - 1) * count / 2;
                    }
                }
            }

        }

        System.out.println(out);
    }