function Main(input) {
  var tmp = input.trim().split(' ')
  var N = parseInt(tmp[0])
  var K = parseInt(tmp[1])

  var ansArray = []
  var result = null

  if (N >= 10 ** 18) {
    result = 0
  }

  while (result === null) {
    N = Math.abs(N - K)
    ansArray.push(N)
    if (ansArray.length > 1) {
      if (ansArray[ansArray.length - 2] < ansArray[ansArray.length - 1]) {
        result = ansArray[ansArray.length - 2]
        break
      }
    }
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))