n, k = map(int, input().split()) if k == 0 or k > n: print(0) elif k % 2 != 0 and k == n // 2 + 1: print(n-1) else: print(n-2)