n,k = map(int, input().split()) l = [1]*n if k==0 or k>n: l = [0]*n l[k-1] = 0 l[-k] = 0 print(sum(l))