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