a1, b1, a2, b2 = map(int,input().split()) for i in range(0,a1*b1+a2+b2): if i%a1==a2 and i%b1==b2: print(i) break