#include using namespace std; using bigint = __int128_t; int go(int v, const vector &p, vector &used) { used[v] = true; int w = p[v]; if (used[w]) return 1; return 1 + go(p[v], p, used); } bigint gcd(bigint a, bigint b) { if (b == 0) return a; return gcd(b, a%b); } string stringify(bigint x) { string ret; while (x) { ret += x % 10 + '0'; x /= 10; } reverse(ret.begin(), ret.end()); return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector x(n); for (int i = 0; i < n; i++) x[i] = i; for (int i = 0; i < k; i++) { int a, b; cin >> a >> b; --a, --b; swap(x[a], x[b]); } vector p(n); for (int i = 0; i < n; i++) p[x[i]] = i; bigint ret = 1; vector used(n); for (int i = 0; i < n; i++) { if (!used[i]) { bigint l = go(i, p, used); ret = ret * l / gcd(ret, l); } } cout << stringify(ret) << endl; return 0; }