#include typedef long long ll; typedef long double lb; using namespace std; #define all(x) (x).begin(), (x).end() #define OVERLOAD_REP(_1, _2, _3, name, ...) name #define REP1(i, n) for (auto i = std::decay_t{}; (i) != (n); ++(i)) #define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i)) #define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__) template bool chmin(T& a, const T& b){if(a > b){a = b; return 1;} return 0;} template bool chmax(T& a, const T& b){if(a < b){a = b; return 1;} return 0;} const ll INF = 1000000000000000000; // 10^18 int main(){ ll a,b; cin >> a >> b; rep(i,100010){ if((i+1) % a == b % (i+1)){ cout << i+1 << endl; return 0; } } return 0; }