n, k = [int(v) for v in input().split(" ")] if k == 0: print(0) elif k > n: print(0) else: if n % 2 == 1 and n == ( 2 * k - 1) : print(n-1) else: print(n-2)