import sys from math import gcd def main(): N = int(sys.stdin.readline()) K = int(sys.stdin.readline()) lines = [] for _ in range(K): X, Y = map(int, sys.stdin.readline().split()) lines.append((X, Y)) # Compute permutation after one shuffle perm = list(range(N + 1)) # 1-based indexing for i in range(1, N + 1): pos = i for X, Y in lines: if pos == X: pos = Y elif pos == Y: pos = X perm[i] = pos # Find cycle lengths and compute LCM visited = [False] * (N + 1) S = 1 for i in range(1, N + 1): if not visited[i]: cycle_length = 0 current = i while not visited[current]: visited[current] = True current = perm[current] cycle_length += 1 S = S * cycle_length // gcd(S, cycle_length) print(S) if __name__ == "__main__": main()