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