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