import sys from math import gcd sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N,K = I(),I() A = [i for i in range(N+1)] for _ in range(K): X,Y = MI() A[X],A[Y] = A[Y],A[X] flag = [0]*(N+1) ans = 1 for i in range(1,N+1): if flag[i]: continue flag[i] = 1 r = 1 a = A[i] while a != i: r += 1 flag[a] = 1 a = A[a] ans = ans*r//gcd(ans,r) print(ans)