import Foundation
struct Solve {
    
    let N: Int
    let K: Int
    
    var ans = 0
    mutating func swapAbs() {
        if abs(ans-K)>ans{
            return
        }
        ans = abs(ans-K)
        swapAbs()
    }
}

let inputLine = readLine()!.components(separatedBy: " ").map({Int($0)!})
let solve = Solve(N: inputLine[0], K: inputLine[1])

print(solve.ans)