output_description: Print the minimum possible value taken by N after Aoki does the operation zero
  or more times.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
attempt: # 振動し始めたら終わり
  
  N, K = map(int, input().split())
  
  A = []
  i = 0
  
  if N - K >= 0:
      A.append(N - K)
      N = N - K
  
  else:
      A.append(K - N)
      N = K - N
  
  if N - K >= 0:
      A.append(N - K)
      N = N - K
  
  else:
      A.append(K - N)
      N = K - N
  
  if N - K >= 0:
      A.append(N - K)
      N = N - K
  
  else:
      A.append(K - N)
      N = K - N
  
  
  i = 2
  if A[i - 2] == A[i]:
      print(min(A))
  
  else:
      while A[i - 2] != A[i]:
          if K == 1:
              print("0")
              break
  
          elif N - K >= 0:
              A.append(N - K)
              N = N - K
              i += 1
              if A[i - 2] != A[i]:
                  print(min(A))
                  break
  
          else:
              A.append(K - N)
              N = K - N
              i += 1
              if A[i - 2] != A[i]:
                  print(min(A))
                  break
  
problem_description: Statement
  
  Given any integer x, Aoki can do the operation below.
  
  Operation: Replace x with the absolute difference of x and K.
  
  You are given the initial value of an integer N. Find the minimum possible
  value taken by N after Aoki does the operation zero or more times.
samples: [{"input": "7 4", "output": "1\n    \n\nInitially, N=7.\n\nAfter one operation, N becomes |7-4| = 3.\n\nAfter two operations, N becomes |3-4| = 1, which is the minimum value taken by\nN.\n\n* * *"}, {"input": "2 6", "output": "2\n    \n\nN=2 after zero operations is the minimum.\n\n* * *"}, {"input": "1000000000000000000 1", "output": "0"}]