#include<bits/stdc++.h> using namespace std; int main(){ long long a,b,x; cin>>a>>b; for(x=1;;x++){ if(a*x%b==1){ cout<<x; break; } } return 0; }