import java.util.Scanner; class Main{ public static void main(String[] args) { new Main().run(); } void run() { Scanner sc=new Scanner(System.in); int A=sc.nextInt(); int B=sc.nextInt(); if(gcd(A,B)!=1) { System.out.println(-1); }else { boolean[] ok=new boolean[100000]; for(int x=0;x<=2*B;++x) { for(int y=0;y<=2*A;++y) { ok[A*x+B*y]=true; } } int ans=0; for(int i=0;i<=2*A*B;++i) { if(!ok[i])++ans; } System.out.println(ans); } } int gcd(int a,int b) { return a==0?b:gcd(b%a,a); } }