n,k = map(int,input().split()) if k==0 or n < k: print(0) else: print(n-2+(k==n-k+1))