import math n, k = (int(i) for i in input().split()) if k == math.ceil(n / 2): print(n - 1) elif not k < 1 and not k > n: print(n - 2) else: print("0")