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