package no101;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = i;
		}
		for(int i=0;i<k;i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			int temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		boolean[] used = new boolean[n];
		long ans = 1;
		for(int i=0;i<n;i++) {
			if (used[i]) {
				continue;
			}
			int length = 0;
			int now = i;
			while(true) {
				if (used[now]) {
					break;
				}
				used[now] = true;
				length++;
				now = a[now];
			}
			ans = lcm(ans, length);
		}
		System.out.println(ans);
	}
	public static long gcd(long a,long b) {
		while(b!=0) {
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}
	public static long lcm(long a,long b) {
		return a * b / gcd(a,b);
	}
}