def xxx(N,K): if K<1: return 0 if K>N: return 0 if K==N+1-K: return N-1 return N-2 N,K=map(int,input().split()) print(xxx(N,K))