a,b = map(int,input().split()) for i in range(1,a+b+1): if a != c and a != b: if a % c == 0 and b % c == 0: print(c) exit() print(-1)