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