def I(): return input() def N(): return int(input()) def M(): return map(int,input().split()) def L(): return list(map(int,input().split())) #----------------------------------------- A,B,a,b = M() for x in range(A*B): if x % A == a and x % B == b: print(x) break