import numpy as np int1 = lambda x: int(x) - 1 N = int(input()) K = int(input()) F = np.arange(N) A = np.arange(N) for _ in range(K): x, y = map(int1, input().split()) F[x], F[y] = F[y], F[x] F_tmp = F.copy() ans = 1 while (F_tmp != A).any(): F_tmp = F_tmp[F] ans += 1 print(ans)