import sys
import math

LOCAL = False

if LOCAL:
    input = open('in.txt', 'r')
    output = open('out.txt', 'w')
else:
    input = sys.stdin
    output = sys.stdout

def gcd(a, b):
    while b != 0:
        r = a % b
        a = b
        b = r
    return a

def lcm(a, b):
    return a / gcd(a, b) * b

def update(k):
    global A, B, minN, minLCM
    Y = (B + k - 1) / k * k
    N = Y - B
    X = A + N
    crt = lcm(X, Y)
    if crt < minLCM:
        minLCM = crt
        minN = N
    elif crt == minLCM and N < minN:
        minN = N

line = input.readline().strip().split(' ')
A = int(line[0])
B = int(line[1])

# ans = -1
# min = 10 ** 18 + 1
# for N in range(10 ** 5):
#     crt = lcm(A + N, B + N)
#     if crt < min:
#         min = crt
#         ans = N

if A > B:
    A, B = B, A

D = B - A

minN = 1
minLCM = lcm(A + 1, B + 1)
i = 1
while i * i <= D:
    if D % i == 0:
        update(i)
        update(D / i)
    i += 1

output.write('{}\n'.format(int(minN)))

input.close()
output.close()