import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] places = new int[n]; for (int i = 0; i < n; i++) { places[i] = i; } int k = sc.nextInt(); for (int i = 0; i < k; i++) { int x = sc.nextInt(); sc.nextInt(); int tmp = places[x]; places[x] = places[x - 1]; places[x - 1] = tmp; } long ans = 1; for (int i = 0; i < n; i++) { int count = 1; int idx = i; while ((idx = places[idx]) != i) { 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); } } }