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