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