#521 ネズミ取りとチーズ N,K=(int(i) for i in input().split()) if K==0 or K>N: print(0) elif N%2==1 and N//2+1==K: print(N-1) else: print(N-2)