A, B, a, b = map(int, input().split()) for x in range(0, 3000*3000): if x%A == a and x%B == b: exit(print(x))