#include using namespace std; void solve() { int a, b; cin >> a >> b; for (int x = 1; x <= 100000; ++x) { if (x % a == b % x) { cout << x << "\n"; return; } } cout << -1 << "\n"; } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }