#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from math import gcd from functools import reduce # %% N = int(readline()) K = int(readline()) m = map(int, read().split()) XY = zip(m, m) # %% P = list(range(N)) for x, y in XY: x -= 1 y -= 1 P[x], P[y] = P[y], P[x] # %% comp = [0] * N size = [] n = 0 for i in range(N): if comp[i]: continue n += 1 comp[i] = n s = 1 while True: i = P[i] if comp[i]: break comp[i] = n s += 1 size.append(s) # %% lcm = reduce(lambda x, y: x * (y // gcd(x, y)), size) print(lcm)