#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,a,b) for (int i=a; i=b; i--) #define fore(i,a) for(auto &i:a) #define pb push_back #define _GLIBCXX_DEBUG template inline bool chmin(T& a, const T& b) {bool c=a>b; if(a>b) a=b; return c;} template inline bool chmax(T& a, const T& b) {bool c=a inline T gcd(T a,T b) {return (b==0)?a:gcd(b,a%b);} template inline T lcm(T a, T b) {return (a*b)/gcd(a,b);} const int inf = INT_MAX / 2; const ll infl = 1LL << 60; using vi = vector; using vvi = vector>; using vvvi = vector>>; using vll = vector; using vvll = vector>; using vvvll = vector>>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a,b; cin >> a >> b; rep(i,1,100001){ if(i % a == b % i){ cout << i << endl; break; } } cout << fixed << setprecision(30); return 0; }