A, B, a, b = map(int, input().split(" ")) for i in range(0, A * B + 1): ans = i * A + a if ans % B == b: print(ans) exit()