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