module main; // https://kmjp.hatenablog.jp/entry/2014/12/12/0900 より import std; void main() { // 入力 int N = readln.chomp.to!int; int K = readln.chomp.to!int; auto R = iota(0, N).array; foreach (_; 0 .. K) { int x, y; readln.chomp.formattedRead("%d %d", x, y); swap(R[x - 1], R[y - 1]); } // 答えの計算と出力 long ans = 1; foreach (i; 0 .. N) { long x, y; for (x = i, y = 0; y == 0 || x != i; y++) x = R[x]; ans = lcm(ans, y); } writeln(ans); }