A, B, a, b = (int(x) for x in input().split()) for i in range(0, 10000000): if i%A == a and i%B == b: print(i) break