import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i; } for (int i = 0; i < k; i++) { int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; int tmp = arr[x]; arr[x] = arr[y]; arr[y] = tmp; } int[] idxes = new int[n]; for (int i = 0; i < n; i++) { idxes[arr[i]] = i; } long ans = 1; for (int i = 0; i < n; i++) { int count = 1; int x = i; while (i != idxes[x]) { x = idxes[x]; count++; } ans = getLCM(ans, count); } System.out.println(ans); } static long getLCM(long x, long y) { return x / getGCD(x, y) * y; } static long getGCD(long x, long y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } }