length, n = map(int, input().split(" ")) ans = max(2 * n - length - 1, 0) print(ans)