N = int(input()) k = int(input()) K = tuple([tuple(map(int, input().split(' '))) for i in range(k)]) count = 0 l = [i for i in range(1, N + 1)] i = 0 while True: x, y = K[i] l[x - 1], l[y - 1] = l[y - 1], l[x - 1] i += 1 if i == k: count += 1 i = 0 for j, n in enumerate(l): if j + 1 != n: break else: break print(count)