import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } void main() { auto N = readln.chomp.to!int; auto K = readln.chomp.to!int; auto X = iota(0, N, 1).array; foreach (i; 0 .. K) { int x, y; readf("%s %s\n", &x, &y); x--; y--; swap(X[x], X[y]); } auto Y = iota(0, N, 1).array; void step() { auto nY = new int[N]; foreach (i; 0 .. N) { nY[i] = Y[ X[i] ]; } Y = nY; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int ans = 1; auto used = new bool[N]; for (int t = 1; t <= N; t++) { step(); foreach (i; 0 .. N) { if (!used[i] && Y[i] == i) { used[i] = true; ans = lcm(ans, t); } } } writeln(ans); }