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