from math import lcm def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def merge(x,y): x = root(x) y = root(y) if x == y: return if x > y: x,y = y,x P[x] += P[y] P[y] = x def same(x,y): return root(x) == root(y) def size(x): x = root(x) return -P[x] N = int(input()) P = [-1] * N K = int(input()) A = list(range(N)) for _ in range(K): x,y = map(int,input().split()) x -= 1 y -= 1 A[x],A[y] = A[y],A[x] for i in range(N): merge(i,A[i]) ans = 1 checked = set() for i in range(N): x = root(i) if x not in checked: checked.add(x) ans = lcm(ans,size(x)) print(ans)