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