#include using namespace std; int main(void){ int a,b; cin>>a>>b; for(int i=1;;i++){ if(i%a==b%i){ cout<