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