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