#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_N 200010 #define PI 3.141592653589 #define ESP 1e-20 #define BS 10 #define MOD 1000000007 #define ZERO 10001 #define YJSNPI 810 #define INF (1LL << 50) #define ADD(a, b) a = (a + (ll)b) % MOD #define MUL(a, b) a = (a * (ll)b) % MOD #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) using namespace std; typedef pair pi; typedef long long ll; int N, K; int goal[110], used[100]; int loop(int at) { if(used[at]) return 0; used[at] = true; return loop(goal[at]) + 1; } ll gcd(ll a, ll b) { if(b == 0) return a; else return gcd(b, a % b); } int main() { cin >> N >> K; for(int i = 0; i < N; i++) { goal[i] = i; } for(int i = 0; i < K; i++) { int l, r; cin >> l >> r; l--; r--; swap(goal[l], goal[r]); } vector vec; for(int i = 0; i < N; i++) { if(!used[i]) vec.push_back(loop(i)); } ll ans = 1; for(int i = 0; i < vec.size(); i++) ans = ans * vec[i] / gcd(ans, vec[i]); cout << ans << endl; }