n,k=map(int,input().split()) l=[1]*n if k==0: print(0) exit() elif k>n: print(0) exit() else: l[k-1]=0 l[-(k-1)]=0 print(l.count(1))