"""
F=open("task_1_input.txt", "r")
N=open("output.txt", "w")

K, T = map(int, F.readline().split())
"""
K = int(input())
T = int(input())

if (T//K)%2==0:
    x=T%K
elif (T//K)%2!=0:
    x=K-T%K

print(x)
    
"""
N.write(str(x))

F.close()
N.close()
"""

45388a0c842d3ccd607668b49a7073d0033b0629
<mask token>

<mask token>
if T // K % 2 == 0:
    x = T % K
elif T // K % 2 != 0:
    x = K - T % K
print(x)
<mask token>

<mask token>
K = int(input())
T = int(input())
if T // K % 2 == 0:
    x = T % K
elif T // K % 2 != 0:
    x = K - T % K
print(x)
<mask token>

"""
F=open("task_1_input.txt", "r")
N=open("output.txt", "w")

K, T = map(int, F.readline().split())
"""
K = int(input())
T = int(input())

if (T//K)%2==0:
    x=T%K
elif (T//K)%2!=0:
    x=K-T%K

print(x)
    
"""
N.write(str(x))

F.close()
N.close()
"""
