A, B, a, b = map(int, input().split()) for i in range(3000**2+1): if i % A == a and i % B == b: print(i) break