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