import sys import math def input(): return sys.stdin.readline().rstrip() def main(): N = int(input()) K = int(input()) *A, = range(N) for i in range(K): X, Y = map(int, input().split()) A[X-1], A[Y-1] = A[Y-1], A[X-1] ans = 1 for i in range(N): c = 1 j = A[i] while j != i: c += 1 j = A[j] ans = math.lcm(ans, c) print(ans) if __name__ == '__main__': main()