#include using namespace std; template inline T gcd(T a, T b) { return __gcd(a, b); } template inline T lcm(T a, T b) { return a / gcd(a, b) * b; } template inline T floor(T a, T b) { return floor(a / b) * b <= a ? floor(a / b) : floor(a / b) - 1; } template inline T ceil(T a, T b) { return floor(a + b - 1, b); } template inline T round(T a, T b) { return floor(a + b / 2); } template inline T mod(T a, T b) { return a - floor(a, b) * b; } template inline T factorial(T n) { return n <= 1 ? 1 : factorial(n - 1) * n; } template inline T square(T n) { return n * n; } template inline T cube(T n) { return n * n * n; } template inline T norm(T x1, T y1, T x2, T y2) { return square(x1 - x2) + square(y1 - y2); } inline long long sqrt(long long n) { return sqrt((long double)n); } int main() { int n, k; cin >> n >> k; vector a(n); iota(a.begin(), a.end(), 0); for (int i = 0; i < k; ++i) { int x, y; cin >> x >> y; swap(a[x - 1], a[y - 1]); } vector used(n); long long res = 1; for (int i = 0; i < n; ++i) { if (used[i]) continue; long long c = 0; for (int j = i; !used[j]; j = a[j]) { used[j] = true; ++c; } res = lcm(res, c); } cout << res << endl; }