A,B,a,b = map(int,input().split()) n = 0 while True: if (A*n+a)%B == B: print(A*n+a) break