N,K=map(int,input().split()) print([N-2+(N//2+N%2==K),0][K<1 or K>N])