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