#include // min, max, swap, sort, reverse, lower_bound, upper_bound #include // bitset #include // isupper, islower, isdigit, toupper, tolower #include // cmathライブラリをインクルード #include // int64_t, int*_t #include // printf #include // deque #include #include // cout, endl, cin #include // map #include // queue, priority_queue #include // set #include // stack #include // string, to_string, stoi #include // tuple, make_tuple #include // unordered_map #include // unordered_set #include // pair, make_pair #include // vector using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define Yout cout << "Yes" << '\n' #define Nout cout << "No" << '\n' #define pb push_back #define mp make_pair #define ft first #define sd second // #define _LIBCPP_DEBUG 0と書く必要があります。 const ll mod = 998244353; const ll mod2 = (long long)1000000007; const ll INF = (long long)2e18; const vector dx = {1, 0, -1, 0}; const vector dy = {0, 1, 0, -1}; // const vector dx = {1, 1, 1, 0, -1, -1, -1, 0}; // const vector dy = {1, 0, -1, -1, -1, 0, 1, 1}; // const vector dx = {1, -1, 1, -1}; // const vector dy = {1, 1, -1, -1}; template void li(T a) { for (auto i : a) { cout << i << ' '; } cout << endl; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool ch(ll l, ll r, ll x) { return l <= x and x < r; } bool chch(ll h, ll w, ll x, ll y) { return ch(0, h, x) and ch(0, w, y); } void solve(){ ll a,b ;cin >> a >> b; for(ll x=1;x<=100000;x++){ if(x%a==b%x){cout << x << endl;return ;} } } int main(){ solve(); }