#include using namespace std; int main(){ int A, B; cin >> A >> B; int x = 1; while(true){ if(x % A == B % x){ cout << x << endl; return 0; } x = x + 1; } return 0; }