a,b,c,d=map(int,input().split()) e=a*b for i in range(e): if i%a==c and i%b==d: print(i) exit()