n, k = map(int, input().split()) t = {i for i in {k, n+1-k} if i in range(1, n+1)} print(n-len(t) if t else 0)