#include //#include using namespace std; //using namespace atcoder; using ll = long long; using ull = unsigned long long; using ld = long double; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll a,b; cin >> a >> b; ll x = 1; while(1){ if(x%a == b%x){ break; } x++; } cout << x << '\n'; }