def f(): n,k = map(int,input().split()) if k==0 or k>n: return 0 return n - (n&1==1 and (n>>1)+1==k and 1 or 2) print(f())