import strutils proc input: string = while true: let t = stdin.readChar if t.isSpaceAscii: break else: result.safeAdd t let N, K = input().parseInt var ans = 0 if K != 0 and K <= N: ans += N - 2 if N mod 2 == 1 and (N + 1) div 2 == K: ans += 1 echo ans