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