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