N, K = list(map(int, input().split())) box = list(range(N)) if K == 0 or K > N: print(0) else: box[K-1] = None box[-K] = None count = 0 for box_in in box: if box_in != None: count += 1 print(count)