#include #define rep(i, a) for (int i = 0; i < (a); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) for (int i = (a) - 1; i >= 0; i--) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 9; int x[1000], y[1000]; int T[100]; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } int main() { int N, K; cin >> N >> K; vector a(N); rep (i, N) a[i] = i; rep (i, K) { cin >> x[i] >> y[i]; x[i]--; y[i]--; } repr (i, K) swap(a[x[i]], a[y[i]]); rep (i, N) { int c = i; int k = 0; do { c = a[c]; k++; } while (c != i); T[i] = k; } ll ans = T[0]; rep (i, N) { ans = lcm(ans, T[i]); } cout << ans << endl; return 0; }