import java.util.*; public class Main_yukicoder101 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); List a = new ArrayList<>(); for (int i = 0; i < n; i++) { a.add(i); } int[] x = new int[k]; int[] y = new int[k]; for (int i = 0; i < k; i++) { x[i] = sc.nextInt() - 1; y[i] = sc.nextInt() - 1; int tmp = a.get(x[i]); a.set(x[i], a.get(y[i])); a.set(y[i], tmp); } List b = new ArrayList<>(a); for (int i = 0; i < n; i++) { b.set(a.get(i), i); } long cnt = 1; long ret = 1; int check = 0; for (; true; ) { int j = check; for (; j < n; j++) { if (a.get(j) != j) { break; } } if (j == n) { System.out.println(ret); break; } else if (j > check) { cnt = ret; for (int i = 0; i < n; i++) { b.set(a.get(i), i); } check = j; } List c = new ArrayList<>(a); for (int i = 0; i < n; i++) { c.set(b.get(i), a.get(i)); } a = c; ret += cnt; } sc.close(); } }