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