#include <vector>
#include <iostream>
using namespace std;
const int inf = 1012345678;
int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = 1; i <= 2 * A * B; ++i) {
		bool ok = false;
		for (int j = 0; j <= B; ++j) {
			for (int k = 0; k <= A; ++k) {
				if (j * A + k * B == i) {
					ok = true;
				}
			}
		}
		if (!ok && i <= A * B) ++ans;
		if (!ok && i > A * B) ans = inf;
	}
	if (ans >= inf) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}