N, K = map(int, input().split()) if K == 0 or K > N: print(0) else: if K % 2 == 0: print(N - 2) elif K % 2 == 1 and K == int((N + 1) / 2): print(N - 1) else: print(N - 2)