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