A,B,a,b = map(int,input().split()) for k in range(A*B): if k%A == a and k%B == b: print(k) ; exit()