import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def main(): def swap(x, y): aa[x], aa[y] = aa[y], aa[x] n = II() k = II() aa = list(range(n)) for _ in range(k): x, y = MI1() swap(x, y) vis = [False] * n ans = 1 for i in range(n): t = 1 while not vis[i]: i = aa[i] vis[i] = True t += 1 ans = lcm(ans, t) print(ans) main()