def egcd(a, b): if a == 0: return (0, 1) else: y, x = egcd(b % a, a) return (x - (b // a) * y, y) A,B,a,b = map(int, input().split(' ')) x,y = egcd(A,B) ans = a * B * y + b * A * x print(ans)