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