a, b, c, d = map(int, input().split()) for x in range(0, 10 ** 7): if not(x % a == c and x % b == d): continue print(x) break