a, b, c, d = [int(x) for x in input().split()] for x in range(9000001): if x % a == c and x % b == d: print(x) exit()