import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,K = map(int,read().split()) if K == 0 or K > N: print(0) else: print(N - len(set([K,N+1-K])))