import math A,B,N,M = map(int, input().split()) if A < B: num = math.ceil(B/M) A += num for i in range(num): B = B - M if A > B: A -= 1 B = B + M print(A) if A > B: num = math.ceil(A/N) B += num for i in range(num): A = A - N if A < B: B -= 1 A = A + N print(B)