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