#include int main() { int A, B; std::cin >> A >> B; for (int x = 1; x <= 100000; ++x) { if (x % A == B % x) { std::cout << x << '\n'; return 0; } } }