#include "bits/stdc++.h" using namespace std; void solve() { long a, b; cin >> a >> b; long c = abs(a - b); if ((a + c) % b || (a + b) % c) { cout << -1 << endl; return; } cout << c << endl; } int main() { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }