#include using namespace std; using ll = long long; int cnt[10005]; int main(){ int a, b; cin >> a >> b; if(gcd(a,b)>1){ cout << -1 << endl; return 0; } int m = a*b-a-b; for(int i = 0; i <= 100; i++){ for(int j = 0; j <= 100; j++){ cnt[a*i+b*j]++; } } int ans = 0; for(int i = 1; i <= m; i++){ if(cnt[i]==0) ans++; } cout << ans << endl; return 0; }