import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!size_t; auto k = readln.chomp.to!size_t; auto ci = iota(k).map!(_ => readln.split.map!(to!size_t).map!("a - 1")).array; auto ni = new size_t[](n); foreach (i; 0..n) { auto p = i; foreach (c; ci) { if (p == c[0]) p = c[1]; else if (p == c[1]) p = c[0]; } ni[i] = p; } auto ri = new size_t[](n); foreach (i; 0..n) { auto p = i, c = 0; do { p = ni[p]; c += 1; } while (p != i); ri[i] = c; } auto r = reduce!((a, b) => a / gcd(a, b) * b)(1.to!size_t, ri); writeln(r); }