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