from itertools import permutations n, m = map(int, input().split()) P = [-1] * n for _ in range(m): pi, ki = map(lambda x: int(x)-1, input().split()) P[ki] = pi ans = 0 for p in permutations(range(n)): flg = 0 for i in range(n): if P[i] != -1 and p[i] != P[i]: flg = 1 if flg: continue for i in range(n): for j in range(i+1, n): ans += p[i] > p[j] print(ans)