Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?

Each toy appears in the shop exactly once. Pairs $(a, b)$ and $(b, a)$ are considered equal. Pairs $(a, b)$, where $a=b$, are not allowed.


-----Input-----

The first line of the input contains two integers $n$, $k$ ($1 \le n, k \le 10^{14}$) — the number of toys and the expected total cost of the pair of toys.


-----Output-----

Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is $k$ burles.


-----Examples-----
Input
8 5

Output
2

Input
8 15

Output
1

Input
7 20

Output
0

Input
1000000000000 1000000000001

Output
500000000000



-----Note-----

In the first example Tanechka can choose the pair of toys ($1, 4$) or the pair of toys ($2, 3$).

In the second example Tanechka can choose only the pair of toys ($7, 8$).

In the third example choosing any pair of toys will lead to the total cost less than $20$. So the answer is 0.

In the fourth example she can choose the following pairs: $(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$. The number of such pairs is exactly $500000000000$.

Difficulty: EASY

Solutions:
(n, m) = map(int, input().split())
x = m // 2
y = n // 2
if m <= n:
	print((m - 1) // 2)
else:
	print(max(0, n - m // 2))


import math
l = list(map(int, input().split()))
count = 0
s = l[0] + l[0] - 1
if l[1] > s:
	print('0')
else:
	k = l[1] / 2
	if k % 1 == 0:
		if k - 1 < l[0] - k:
			count += k - 1
		else:
			count += l[0] - k
		print(int(count))
	else:
		z1 = math.ceil(k)
		z2 = math.floor(k)
		if z2 - 1 < l[0] - z1:
			count += z2 - 1
		else:
			count += l[0] - z1
		print(count + 1)


import math
(n, k) = map(int, input().split())
if k < 2 * n:
	if k <= n:
		mn = 1
		mx = k - mn
	else:
		mx = n
		mn = k - mx
	print(math.ceil((mx - mn) / 2))
else:
	print(0)


(n, k) = map(int, input().split())
if k <= n:
	if k % 2 == 0:
		print(k // 2 - 1)
	else:
		print(k // 2)
else:
	res = n - k // 2
	if res > 0:
		print(res)
	else:
		print(0)


s = input()
s = s.split(' ')
a = int(s[0])
b = int(s[1])
if b % 2 == 0:
	c = int(b / 2 - 1)
else:
	c = int(b / 2)
l = b - c
h = b - 1
ans = 0
if l > a:
	ans = 0
elif a < h:
	ans = a - l + 1
else:
	ans = h - l + 1
print(ans)


(n, k) = map(int, input().split())
if n >= k:
	if k % 2 == 0:
		k -= 1
	print(k // 2)
	exit(0)
ans = 2 * n - k
if ans <= 0:
	print(0)
else:
	print((ans + 1) // 2)


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


import sys
import math
import collections
import heapq
input = sys.stdin.readline
(n, k) = (int(i) for i in input().split())
if 2 * n - 1 < k:
	print(0)
elif k > n:
	k1 = k - n
	print((n - k1 + 1) // 2)
elif k <= n:
	if k % 2 == 0:
		print(math.ceil((k - 1) / 2) - 1)
	else:
		print(math.ceil((k - 1) / 2))


(maxi, tot) = map(int, input().split())
if tot == 1 or tot == 2:
	print(0)
	exit()
bi = tot // 2 + 1
print(max(0, min(tot - bi, maxi - bi + 1)))


(n, k) = map(int, input().split())
print(max(0, min(n, k - 1) - (k // 2 + 1) + 1))


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


import math
(n, k) = map(int, input().split())
a = 0
if n == 0 or k == 0:
	a = 0
elif k == 2:
	a = 0
elif k / 2 >= n:
	a = 0
elif n >= k:
	a += (k - 1) // 2
else:
	a += (n * 2 - k + 1) // 2
print(a)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
if n == 1:
	ans = 0
elif n + n - 1 < k:
	ans = 0
elif k % 2 == 0:
	ans = min(k / 2 - 1, n - k / 2)
else:
	ans = min(k // 2, n - k // 2)
print(int(ans))


(n, k) = (int(x) for x in input().split())
if n >= k - 1:
	print((k - 1) // 2)
	quit()
elif k % 2 == 0:
	if n <= k // 2:
		print(0)
		quit()
	else:
		print(n - k // 2)
		quit()
elif n <= k // 2:
	print(0)
	quit()
else:
	print(n - k // 2)
	quit()


(n, k) = input().split()
n = int(n)
k = int(k)
c = 0
if k <= n:
	c = k - 1
elif k <= 2 * n:
	c = 2 * n - k + 1
print(int(c / 2))


(n, k) = (int(x) for x in input().split())
if k > n * 2 or k < 3:
	print(0)
elif n >= k - 1:
	print(k - k // 2 - 1)
else:
	print(n - k // 2)


(n, k) = map(int, input().split())
import math
if k % 2 == 0:
	p = k // 2
	print(max(min(p - 1, n + 1 - (p + 1)), 0))
else:
	print(max(min(math.floor(k / 2), n + 1 - math.ceil(k / 2)), 0))


I = lambda : map(int, input().split())
(n, m) = I()
if m <= n:
	if m % 2 == 0:
		exit(print(m // 2 - 1))
	else:
		exit(print(m // 2))
if (2 * n - m) % 2 == 0:
	print(max(0, (2 * n - m) // 2))
else:
	print(max(0, (2 * n - m) // 2 + 1))


(n, k) = map(int, input().split())
if k <= n:
	print((k - 1) // 2)
elif k - n > n - 1:
	print(0)
else:
	a = n
	b = k - n
	print((a - b + 1) // 2)


import math
(n, k) = map(int, input().split())
if 2 * n - 1 < k:
	ans = 0
elif 2 * n - 1 >= k and k > n:
	ans = math.ceil(k / 2) - (k - n)
else:
	ans = math.ceil(k / 2) - 1
print(ans)


import math
(n, m) = map(int, input().split())
if n >= m:
	print(math.floor((m - 1) / 2))
else:
	o = m - n
	o = n - o + 1
	if o > 1:
		print(o // 2)
	else:
		print(0)


tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
a = b = 0
if n == 1 or k < 3:
	print('0')
elif n == 2 and k == 3:
	print('1')
elif 3 <= k and k <= 2 * n - 1:
	if 3 <= k and k <= n + 1:
		b = k - 1
		a = 1
	else:
		b = n
		a = k - n
	if k % 2:
		print(int((b - a) / 2) + 1)
	else:
		print(int((b - a) / 2))
else:
	print('0')


import math
(n, k) = map(int, input().strip().split())
if n >= k:
	a = math.ceil(k / 2) - 1
elif n * 2 <= k:
	a = 0
else:
	if k % 2 == 0:
		k += 1
	a = math.floor((2 * n - k) / 2) + 1
print(int(a))


(num_toys, burles_cost) = map(int, input().split())
higher = min(num_toys, burles_cost - 1)
smaller = burles_cost - higher
solution = 0
if smaller < higher:
	solution = 1
	remaining_numbers = higher - 1 - smaller
	solution += remaining_numbers // 2
print(solution)


import math
(N, K) = [int(x) for x in input().split(' ')]
if N + (N - 1) < K:
	print(0)
else:
	value = 0
	if N >= K - 1:
		value = math.floor((K - 1) / 2)
	else:
		length = N - (K - N - 1)
		value = math.floor(length / 2)
	print(value)


(n, k) = list(map(int, input().split()))
if k % 2 == 1:
	a1 = k // 2
	a2 = k // 2 + 1
else:
	a1 = k // 2 - 1
	a2 = k // 2 + 1
print(max(0, min(a1, n - a2 + 1)))


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, k) = rint()
kk = k - 1
if kk < n:
	print(kk // 2)
	exit()
ans = (n - (k - n) + 1) // 2
if ans < 0:
	print(0)
else:
	print(ans)


a = input()
a = list(map(int, a.split()))
if a[1] == 1 or a[1] == 2 or a[1] > 2 * a[0] - 1:
	print('0')
elif a[1] <= a[0]:
	if a[1] % 2 == 0:
		print(int((a[1] - 2) / 2))
	else:
		print(int((a[1] - 1) / 2))
else:
	n = a[0]
	k = a[1]
	if n % 2 == 0 and k % 2 == 0:
		print(int((2 * n - k) / 2))
	if n % 2 == 0 and k % 2 == 1:
		print(int((2 * n + 1 - k) / 2))
	if n % 2 == 1 and k % 2 == 0:
		print(int((2 * n - k) / 2))
	if n % 2 == 1 and k % 2 == 1:
		print(int((2 * n + 1 - k) / 2))


while True:
	enkay = input().split()
	n = int(enkay[0])
	k = int(enkay[1])
	print(max(0, min(k - 1, n) - k // 2))
	break


from math import ceil
(n, k) = map(int, input().split())
if k >= 2 * n or k < 3:
	print(0)
elif k <= n:
	print((k - 1) // 2)
else:
	x = 2 * n - k
	print(int(ceil(x / 2)))


lineone = input().split(' ')
n = int(lineone[0])
k = int(lineone[1])

def countpairs(n, k):
	if k > n + n - 1:
		return 0
	limit = k // 2
	if k <= n:
		return k - limit - 1
	else:
		return n - limit
print(countpairs(n, k))


from math import floor, ceil
cnt = 0
(n, k) = map(int, input().split())
if n >= k:
	print(floor(k / 2 - 0.1))
elif n - k / 2 < 0:
	print(0)
else:
	print(ceil(n - k / 2))


def toys(m, k):
	start = 1 if k <= m else k - m
	end = k - start if k <= m else m
	if start >= m:
		return 0
	return (end - start + 1) // 2
inputs = input().split(' ')
print(toys(int(inputs[0]), int(inputs[1])))


(a, b) = map(int, input().split())
if a > b:
	if b % 2 == 1:
		print(b // 2)
	else:
		print(b // 2 - 1)
elif a <= b // 2:
	print(0)
elif a > b // 2 and a < b:
	if b % 2 == 1:
		print(b // 2 - b + a + 1)
	else:
		print(b // 2 - b + a)
elif b % 2 == 0:
	print(b // 2 - 1)
else:
	print(b // 2)


(n, k) = input().split()
n = int(n)
k = int(k)
if k <= n:
	if int(k / 2) == k / 2:
		print(int(k / 2) - 1)
	else:
		print(int(k / 2))
else:
	t = k - n
	if int(k / 2) == k / 2:
		if int(k / 2) - t <= 0:
			print(0)
		else:
			print(int(k / 2) - t)
	elif int(k / 2) - t + 1 <= 0:
		print(0)
	else:
		print(int(k / 2) - t + 1)


(n, k) = map(int, input().split())
count = 0
i = 1
while i < n:
	diff = k - i
	if diff <= 0:
		break
	elif diff > n:
		i += diff - n
		continue
	else:
		diff = diff - i
		if diff % 2 == 1:
			diff += 1
		count += diff // 2
		break
print(count)


(n, k) = map(int, input().split())
l = r = 0
if k > n:
	r = n
	l = k - n
else:
	r = k - 1
	l = 1
ans = 0
if r > l:
	ans = (r - l + 1) // 2
print(ans)


def solve(n, k):
	first = max(1, k - n)
	last = min(k // 2, n)
	return max(0, last - first + k % 2)

def brute(n, k):
	ans = 0
	for a in range(1, n + 1):
		b = k - a
		if a < b and b <= n:
			ans += 1
	return ans
(n, k) = map(int, input().split())
print(solve(n, k))


import math
(n, k) = list(map(int, input().split()))
if k <= n + 1:
	print(max(0, math.ceil(k / 2) - 1))
else:
	k = 2 * n + 2 - k
	print(max(0, math.ceil(k / 2) - 1))


def input_ints():
	return list(map(int, input().split()))

def output_list(v):
	print(' '.join((str(x) for x in v)))

def main():
	(n, k) = input_ints()
	if k <= n:
		ans = (k - 1) // 2
	elif k <= 2 * n:
		ans = (2 * n - k + 1) // 2
	else:
		ans = 0
	print(ans)
main()


(n, m) = map(int, input().split(' '))
from math import *
if n >= m:
	print(int(ceil(m / 2)) - 1)
else:
	want = int(ceil(m / 2))
	tot = 0
	if n >= want:
		want = max(want, n)
		want2 = m - want
		diff = want - want2
		tot = int(ceil(diff / 2))
	print(tot)


(n, k) = [int(x) for x in input().split()]
diff = k - n - 1
if diff <= 0:
	if k % 2 == 0:
		res = int(k / 2 - 1)
	else:
		res = int(k / 2)
elif k % 2 == 0:
	res = int(k / 2 - 1 - diff)
else:
	res = int(k / 2 - diff)
if res >= 0:
	print(res)
else:
	print(0)


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
if 2 * n - 1 < k:
	print(0)
elif k > n:
	x = k - n
	cnt = 1
	cnt += n - x
	print(cnt // 2)
else:
	cnt = (k - 1) // 2
	print(cnt)


trash = [int(i) for i in input().split()]
a = trash[0] * 2 + 1
if trash[1] > a:
	print(0)
elif trash[0] >= trash[1]:
	print(int((trash[1] - 1) / 2))
else:
	result = int((trash[1] - 1) / 2) - (trash[1] - trash[0]) + 1
	print(result)


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


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


(n, k) = [int(r) for r in input().split()]
if k <= n + 1:
	print((k - 1) // 2)
else:
	print(max(0, n - k + n + 1) // 2)


import sys
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(N, K) = getInts()
	if K >= 2 * N or K <= 2:
		return 0
	if K <= N:
		return K // 2 - (K % 2 == 0)
	return K // 2 - (K % 2 == 0) - (K - N) + 1
print(solve())


def f():
	(n, k) = map(int, input().split())
	if k > 2 * n - 1:
		return 0
	if k <= n:
		return (k - 1) // 2
	else:
		return n - k // 2
res = f()
print(res)


(n, k) = list(map(int, input().split()))
if k == 1 or n == 1:
	print(0)
	return
if k > 2 * n - 1:
	print(0)
else:
	(left, right) = (0, min(n - 1, k - 1))
	while left != right - 1:
		mid = (left + right) // 2
		if k - mid <= n:
			right = mid
		else:
			left = mid
	print(max(0, min(n, k - 1) - right + 1) // 2)


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


(n, k) = map(int, input().split())
if k % 2:
	x = k // 2
else:
	x = k // 2 - 1
if x >= n:
	print(0)
else:
	z = k - x
	ans = n - z + 1
	print(min(x, ans))


(n, m) = input().split()
n = int(n)
m = int(m)
if m % 2 == 0:
	k = m / 2
	j = k
	k = k - 1
	j = j + 1
else:
	k = int(m / 2)
	j = k + 1
print(int(max(0, min(k, n - j + 1))))


(a, b) = map(int, input().split())
if 2 * a <= b:
	print(0)
elif a < b:
	total = 2 * a - b + 1
	print(total // 2)
elif a >= b:
	if b % 2 == 0:
		b -= 1
	print(b // 2)


(number, made) = map(int, input().split())
if number >= made:
	print((made - 1) // 2)
elif number + number - 1 < made:
	print(0)
else:
	foo = made - number
	bar = number - foo + 1
	print(bar // 2)


from collections import *
from math import *
(a, b) = list(map(int, input().split()))
ub = min(a, b - 1)
lb = b // 2 + 1
print(max(0, ub - lb + 1))


(n, k) = map(int, input().split())
k2 = (k - 1) // 2
if n >= k - 1:
	ans = k2
elif n <= k2:
	ans = 0
else:
	ans = k2 - k + n + 1
print(ans)


import operator as op
from functools import reduce

def read_ints():
	return [int(s) for s in input().split(' ')]

def is_even(k):
	return k % 2 == 0

def solve(n, k):
	if n >= k - 1:
		return (k - 1) // 2
	elif n < k // 2 + 1:
		return 0
	else:
		n_min = k - n
		return (n - n_min + 1) // 2
(n, k) = read_ints()
print(solve(n, k))


def fun(n, k):
	if n == 1 or k == 1:
		return 0
	elif k >= n * 2:
		return 0
	elif k > n:
		return n - k // 2
	elif k == n and k % 2 == 0:
		return k // 2 - 1
	elif k == n and k % 2 != 0:
		return k // 2
	elif k % 2 == 0:
		return k // 2 - 1
	elif k % 2 != 0:
		return k // 2
	return 0
(n, k) = map(int, input().rstrip().split())
print(fun(n, k))


(n, k) = [int(i) for i in input().split()]
a = (k - 1) // 2
b = k - n - 1
if b < 0:
	b = 0
c = a - b
if c < 0:
	c = 0
print(c)


def solve():
	(n, k) = map(int, input().split())
	if k == 1:
		return 0
	if 2 * n - 1 < k:
		return 0
	if 2 * n - 1 == k:
		return 1
	if k - 2 < n and k <= n + 1:
		return (k - 1) // 2
	if k - n < n:
		return (n - (k - n) + 1) // 2
print(solve())


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


(n, k) = [int(x) for x in input().split()]
if k <= n:
	if k % 2 == 0:
		flag = 1
	else:
		flag = 0
	print(k // 2 - flag)
else:
	if k // 2 > n:
		flag = 0
	else:
		flag = 1
	print((n - k // 2) * flag)


def solve(N, K):
	if K - 1 <= N:
		return (K - 1) // 2
	d = K - 1 - N
	(a, b) = (1 + d, K - 1 - d)
	if a >= b:
		return 0
	return (b - a + 1) // 2

def main():
	(N, K) = [int(e) for e in input().split(' ')]
	print(solve(N, K))
main()


(n, k) = map(int, input().split())
if k % 2 == 0:
	a = k // 2 - 1
	b = k // 2 + 1
else:
	a = k // 2
	b = k // 2 + 1
print(max(0, min(a, n - b + 1)))


(n, k) = map(int, input().split())
if k % 2 == 0:
	a = k // 2 + 1
else:
	a = (k + 1) // 2
ans = min(n + 1, k) - a
if ans < 0:
	ans = 0
print(ans)


import math

def solve():
	(n, k) = map(int, input().split())
	h = k / 2
	if n < k:
		ans = n - math.floor(h)
	elif k <= n:
		ans = math.ceil(h) - 1
	ans = max(0, ans)
	print(ans)
solve()


(n, k) = list(map(int, input().split()))
if k % 2 == 0:
	down = int(k / 2 + 1)
	if down > n:
		print(0)
		return
	else:
		up = min(k - 1, n)
		print(up - down + 1)
else:
	down = int((k + 1) / 2)
	if down > n:
		print(0)
		return
	else:
		up = min(k - 1, n)
		print(up - down + 1)


(n, k) = map(int, input().split())
a = min(n, k - 1)
b = k - a
if a > n or b > n:
	print(0)
else:
	print(abs(a - b + 1) // 2)


parameters = [int(s) for s in input().split(' ')]
(n, k) = parameters

def eval():
	if k > 2 * n - 1:
		return 0
	if n >= k:
		return k // 2 if k % 2 else k // 2 - 1
	else:
		return n - k // 2
print(eval())


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


import math

class CodeforcesTask1023BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]

	def process_task(self):
		if self.n_k[1] == self.n_k[0]:
			ways = math.ceil((self.n_k[0] * 2 - self.n_k[1]) / 2) - 1
		elif self.n_k[1] < self.n_k[0] + 1:
			ways = math.ceil(self.n_k[1] / 2) - 1
		else:
			ways = math.ceil((self.n_k[0] * 2 - self.n_k[1]) / 2)
		self.result = str(max(0, ways))

	def get_result(self):
		return self.result
Solution = CodeforcesTask1023BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import math
(n, k) = [int(i) for i in input().split()]

def ceildiv(a, b):
	(quot, mod) = divmod(a, b)
	return quot if mod == 0 else quot + 1

def pairs(a, b):
	return ceildiv(b - a, 2)
if k < n:
	print(pairs(1, k - 1))
elif n + n - 1 < k:
	print(0)
else:
	b = n if k != n else n - 1
	print(pairs(k - b, b))


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


data = [int(x) for x in input().split()]
n = data[0]
k = data[1]
dev_1 = n - (k // 2 + 1) + 1
dev_2 = k // 2 - (1 - k % 2)
print(max(min(dev_1, dev_2), 0))


X = list(map(int, input().split()))
(First, Second) = (X[1] // 2 if X[1] % 2 == 1 else X[1] // 2 - 1, X[1] // 2 + 1 if X[1] % 2 == 1 else X[1] // 2 + 1)
print(min(First, max(0, X[0] - Second + 1)))


def res(n, k):
	max_res = min(n, k - 1)
	min_res = max(1, k - max_res)
	return max(0, (max_res + 1 - min_res) // 2)
num = [int(i) for i in input().split(' ')]
print(res(*num))


a = input()
lst = []
a_1 = ''
for i in range(len(a)):
	if a[i] != ' ':
		a_1 = a_1 + a[i]
	else:
		lst.append(int(a_1))
		a_1 = ''
lst.append(int(a_1))
if lst[1] > 2 * lst[0] - 1:
	print(0)
else:
	countr = 0
	if lst[1] % 2 == 1:
		countr = (lst[1] - 1) // 2
	else:
		countr = (lst[1] - 2) // 2
	if lst[1] > lst[0] + 1:
		countr = countr - lst[1] + lst[0] + 1
	print(countr)


def readNums(type=int):
	return list(map(type, input().split()))
(n, k) = readNums()
if n == 1 or k < 3 or n + n - 1 < k:
	print(0)
elif k <= 1 + n:
	print(k - 1 >> 1)
else:
	k -= n
	print(n - k + 1 >> 1)


[n, k] = [int(x) for x in input().split()]
m1 = -1
m2 = -1
if k <= n:
	m1 = 1
	m2 = k - 1
else:
	diff = k - n
	m1 = diff
	m2 = k - diff
if m2 <= m1:
	print('0')
else:
	tot = m2 - m1 + 1
	print(tot // 2)


(n, k) = [int(x) for x in input().split()]
if k > n + n - 1:
	print(0)
	exit()
if k == n + n - 1 and n != 1:
	print(1)
	exit()
if k <= n:
	print((k - 1) // 2)
	exit()
print((2 * n - k + 1) // 2)


(n, k) = map(int, input().split())
(a, b) = (1, n)
if a + b < k:
	a += k - a - b
if a + b > k:
	b -= a + b - k
if 3 > k or 2 * n - 1 < k:
	print(0)
else:
	print((b - a + 1) // 2)


def main():
	(n, k) = map(int, input().split())
	max_val = n
	min_val = k - n
	if min_val <= 0:
		max_val += min_val - 1
		min_val = 1
	if min_val >= max_val:
		print(0)
		return
	ans = (max_val - min_val + 1) // 2
	print(ans)
main()


def POTs():
	n_k = input()
	x = n_k.find(' ')
	n = int(n_k[:x])
	k = int(n_k[x + 1:])
	if k < 2 * n:
		if k % 2 == 0:
			return int(min(k / 2 - 1, n - k / 2))
		else:
			return int(min((k - 1) / 2, n - (k - 1) / 2))
	else:
		return 0
print(POTs())


(n, k) = map(int, input().split())
if n + n - 1 < k:
	print('0')
elif n >= k:
	t1 = k - 1
	t2 = 1
	ans = t1 - t2
	ans -= 1
	ans //= 2
	ans += 1
	print(ans)
else:
	t1 = n
	t2 = k - n
	ans = t1 - t2
	ans -= 1
	ans //= 2
	ans += 1
	print(ans)


from math import *
(n, m) = map(int, input().split())
q1 = m // 2
q2 = m // 2 + m % 2
maxx = min(q1, n - q2 + 1)
if m % 2 == 0:
	maxx -= 1
print(max(maxx, 0))


(n, k) = map(int, input().split())
if k > n + n - 1:
	print(0)
	exit(0)
if k - 1 <= n:
	ml = 1
	mr = k - 1
	print((mr - ml + 1) // 2)
else:
	mr = n
	ml = k - n
	print((mr - ml + 1) // 2)


(n, k) = map(int, input().split())
if n + n - 1 < k:
	print(0)
elif n == 1:
	print(0)
elif k <= n:
	i = 0
	j = k - 1
	print((j - i) // 2)
else:
	i = k - n
	j = n
	print((j - i + 1) // 2)


(n, k) = [int(i) for i in input().split()]
if k % 2 == 0:
	z = k // 2
else:
	z = k // 2 + 1
if k - 1 >= n:
	mm = n
else:
	mm = k - 1
if k % 2 != 0:
	print(max(0, mm - z + 1))
else:
	print(max(0, mm - z))


from math import ceil
t = 1
for test in range(1, t + 1):
	(n, m) = map(int, input().split())
	if n + n - 1 < m:
		print(0)
	else:
		tmp = m - n
		if tmp < 1:
			print((m - 1) // 2)
		else:
			print(ceil((n - tmp) / 2))


a = [int(x) for x in input().split()]
n = a[0]
k = a[1]
count = 0
if k >= 2 * n:
	output = 0
elif k <= n:
	if k % 2 != 0:
		output = (k - 1) / 2
	else:
		output = (k - 2) / 2
else:
	temp = 2 * n - k + 1
	if k % 2 == 1:
		output = temp / 2
	else:
		output = (temp - 1) / 2
print(int(output))


(n, k) = [int(a) for a in input().split()]
length = 0
if k >= 2 * n:
	print(0)
elif n == k:
	if n % 2 == 0:
		print(int(n / 2 - 1))
	else:
		print(int(n // 2))
elif n < k:
	length = n + 1 - (k - n)
	print(int(length // 2))
elif k % 2 == 0:
	print(int(k / 2 - 1))
else:
	print(int(k // 2))


(n, k) = map(int, input().split())
if k % 2 == 0:
	down = int(k / 2 + 1)
	if down > n:
		print(0)
		exit(0)
	else:
		up = min(k - 1, n)
		print(up - down + 1)
else:
	down = int((k + 1) / 2)
	if down > n:
		print(0)
		exit(0)
	else:
		up = min(k - 1, n)
		print(up - down + 1)


(n, k) = map(int, input().split())
if k < 3:
	print(0)
	exit(0)
if n >= k:
	print((k - 1) // 2)
else:
	print(max((n - (k - n) + 1) // 2, 0))


def main():
	(n, k) = [int(c) for c in input().split()]
	res = max(0, (k - 1) // 2 - max(0, k - n - 1))
	print(res)
main()


(n, m) = [int(i) for i in input().split()]
if 2 * n - 1 < m:
	print(0)
else:
	i = (m - 1) // 2
	t = 2 * i + 1
	z1 = n + i
	z2 = m
	if z2 < 1 + n:
		z2 = 1 + n
		z = z1 - z2
	else:
		z = abs(z2 - z1)
	print(z + 1)


import math
(n, m) = map(int, input().split())
c = 0
if n == 0 or m == 0:
	c = 0
elif m == 2:
	c = 0
elif m / 2 >= n:
	c = 0
elif n >= m:
	c += (m - 1) // 2
else:
	c += (n * 2 - m + 1) // 2
print(c)


from math import ceil
(n, k) = [int(__) for __ in input().strip().split()]
if k <= n:
	print(ceil(k / 2) - 1)
elif k >= 2 * n:
	print(0)
else:
	le = n - k // 2
	print(le)


import sys, collections
(n, k) = map(int, sys.stdin.readline().split())
if n >= k:
	if k % 2 == 0:
		print(k // 2 - 1)
	else:
		print(k // 2)
elif n < k // 2:
	print(0)
else:
	print(n - k // 2)


from math import ceil
(n, k) = map(int, input().split())
if k <= 1:
	print(0)
elif k > 2 * n - 1:
	print(0)
else:
	low = 1
	high = n
	while low <= high:
		mid = low + high >> 1
		if k - mid <= n:
			high = mid - 1
		else:
			low = mid + 1
	print(ceil((k - 2 * low) / 2))


import logging
fmt = '%(levelname)s - %(name)s (line:%(lineno)s) - %(message)s'
formatter = logging.Formatter(fmt)
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
ch.setFormatter(formatter)
logger = logging.getLogger('pair_of_toys')
logger.setLevel(logging.ERROR)
logger.addHandler(ch)

def solve(n, k):
	if k <= 2 or k > 2 * n - 1:
		return 0
	if k > n + 1:
		(l, r) = (k - n, n)
	else:
		(l, r) = (1, k - 1)
	if l >= r:
		return 0
	return (r - l + 1) // 2

def main():
	(n, k) = map(int, input().strip().split())
	result = solve(n, k)
	print(result)
main()


(n, k) = [int(x) for x in input().split()]
m = k / 2
m2 = k // 2
if m2 * 2 == k:
	l = m2 - 1
	h = n - m2
else:
	l = m2
	h = n - m2
ans = min(l, h)
if ans < 0:
	ans = 0
print(ans)


(n, k) = map(int, input().split())
ans = k // 2
ans -= max(min(k - n - 1, k // 2), 0)
if k % 2 == 0 and k // 2 <= n:
	ans -= 1
	ans = max(0, ans)
print(ans)


(n, m) = map(int, input().split())
p = (m - 1) // 2
if n >= m - 1:
	print(p)
elif n > p:
	print(p - m + n + 1)
else:
	print(0)


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(n, k) = list(map(int, input().split(' ')))
	minx = max(1, k - n)
	maxx = min(n, (k - 1) // 2)
	if minx > maxx:
		print(0)
	else:
		print(maxx - minx + 1)

def __starting_point():
	main()
__starting_point()


def combinations(n, s):
	r = 0
	if s <= n:
		r = int((s - 1) / 2)
	elif s % 2 == 0:
		r = int(n - s / 2)
	else:
		r = int(n - (s - 1) / 2)
	if r <= 0:
		return 0
	else:
		return r
(n, s) = map(int, input().split(' '))
print(combinations(n, s))


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
(n, k) = mi()
y = min(n, k - 1)
x = k - y
ans = 0
if x < y:
	dif = y - x
	ans = (dif + 1) // 2
print(ans)


from sys import stdin, stdout
from collections import deque
(n, k) = map(int, stdin.readline().split())
n = min(n, k - 1)
(l, r) = (0, n + 1)
while r - l > 1:
	m = l + r >> 1
	if k - m <= n:
		r = m
	else:
		l = m
ans = n - r + 1
if not k & 1 and k // 2 <= n:
	ans -= 1
ans //= 2
stdout.write(str(ans))


import math
(n, k) = [int(i) for i in input().split()]
maxm = k - n
if maxm >= n:
	print(0)
elif maxm > 0:
	print(math.ceil((n - maxm) / 2))
else:
	print(math.ceil((k - 2) / 2))


import math

def solve():
	(n, k) = [int(x) for x in input().split(' ')]
	if k > 2 * n - 1:
		return 0
	elif k > n:
		return (n - (k - n) + 1) // 2
	if k % 2 == 0:
		return (k - 2) // 2
	return k // 2
print(solve())


def f(ll):
	(n, k) = ll
	f = k // 2 + 1
	e = min(k - 1, n)
	return max(0, e - f + 1)
l = list(map(int, input().split()))
print(f(l))


import sys
(n, k) = list(map(int, input().split(' ')))
k = min(k, 2 * n + 2 - k)
print(max(0, int((k - 1) / 2)))


import math as m
(n, k) = map(int, input().split())
if n <= k / 2:
	print(0)
else:
	print(min(n - m.floor((k + (k + 1) % 2) / 2), m.floor((k - (k + 1) % 2) / 2)))


s = input().split()
(a, b) = (int(s[0]), int(s[1]))
ll = b - 1
ls = 2
if ll > a:
	ll = a
if ls * 2 <= b:
	ls = b // 2 + 1
res = ll - ls + 1
print(res if res > 0 else 0)


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


(n, k) = map(int, input().split())
r = divmod(k, 2)
r = r[0] + 1
if r > n:
	print('0')
else:
	print(k - r if k <= n else n - r + 1)


from sys import stdin, stdout
(n, k) = tuple(map(int, input().split()))
if k >= 2 * n:
	print(0)
	exit()
if k <= n:
	print((k - 1) // 2)
elif k % 2 == 0:
	k = k // 2
	print(min(n - k, k - 1))
else:
	k = k // 2
	(a, b) = (k, k + 1)
	print(1 + min(n - b, a - 1))


(n, m) = list(map(int, input().strip().split()))
if n >= m:
	if m % 2 == 0:
		print((m - 2) // 2)
	else:
		print((m - 1) // 2)
else:
	if m % 2 == 0:
		l1 = (m - 2) // 2
		l1 = l1 - (m - n - 1)
	else:
		l1 = (m - 1) // 2
		l1 = l1 - (m - n - 1)
	if l1 <= 0:
		print(0)
	else:
		print(l1)


(n, k) = map(int, input().split())
mx = k // 2
if k % 2 == 0:
	mx -= 1
my = max(1, k - n)
print(max(mx - my + 1, 0))


import math

def main():
	(n, m) = map(int, input().split())
	print(max(0, min(n, m - 1) - (m // 2 + 1) + 1))
main()


(n, k) = [int(i) for i in input().split(' ')]
if k > n + n - 1:
	print(0)
else:
	minus = max(0, k - n - 1)
	if k % 2 == 0:
		print(k // 2 - 1 - minus)
	else:
		print(k // 2 - minus)


import math
(n, k) = [int(x) for x in input().split(' ')]
if k > 2 * n - 1:
	print(0)
else:
	lowest = max(k - n, 1)
	highest = max(k - n, math.ceil(k / 2) - 1)
	print(highest - lowest + 1)


(n, m) = map(int, input().split())
print(max(min((m + 1) // 2 - 1, n - m // 2), 0))


(n, k) = map(int, input().split())
if k <= n:
	print((k - 1) // 2)
	exit()
elif 2 * n - 1 < k:
	print(0)
	exit()
else:
	tmp = k - n
	if tmp == n - 1:
		print(1)
		exit()
	elif (n - tmp) % 2:
		print((n - tmp) // 2 + 1)
	else:
		print((n - tmp) // 2)


s = list(map(int, input().split()))
(n, k) = (s[0], s[1])
if n + n - 1 < k:
	print(0)
else:
	p = k // 2
	t = min(n, k - 1)
	print(t - p)


l = list(map(int, input().split()))
n = l[0]
m = l[1]
if m > n and 2 * n < m:
	print(0)
elif n >= m:
	print(int((m - 1) / 2))
else:
	print(int((2 * n - m + 1) / 2))


(n, k) = [int(x) for x in input().split()]
print(max(0, min(k - 1, n) - k // 2))


(n, k) = map(int, input().split())
if k >= n * 2:
	print(0)
else:
	a = n // 2 - (n // 2 - k // 2)
	if k > n:
		a = n - a
	if k <= n and k % 2 == 0:
		a -= 1
	print(a)


import math
(n, k) = (int(x) for x in input().split())
ans = 0
if k > 2 * n - 1:
	print(0)
	exit(0)
elif n > k:
	if k % 2 == 0:
		print(int(k / 2) - 1)
	else:
		print(k // 2)
elif n == k:
	if k % 2 == 0:
		print(k // 2 - 1)
	else:
		print(k // 2)
elif k == 2 * n - 1:
	print(1)
elif k > n:
	if k % 2 == 0:
		print(k // 2 - (k - n))
	else:
		print(k // 2 - (k - n) + 1)


def cin(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(n, k) = cin()
ans = (k - 1) // 2 - max(k - 1 - n, 0)
print(max(ans, 0))


(n, k) = map(int, input().split())
if k % 2 == 0:
	if k // 2 >= n:
		print(0)
		exit()
	l = k // 2 - 1
	if k - 1 > n:
		l -= k - 1 - n
	print(l)
if k % 2 == 1:
	if k // 2 >= n:
		print(0)
		exit()
	l = k // 2
	if k - 1 > n:
		l -= k - 1 - n
	print(l)


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


from collections import Counter
(n, k) = list(map(lambda x: int(x), input().split()))
if 2 * n - 1 == k or n == 1:
	if 2 * n - 1 == k and n != 1:
		res = 1
	else:
		res = 0
elif 2 * n - 1 < k:
	res = 0
elif n < k:
	if k % 2 == 0 and k / 2 <= n:
		res = max(0, int((2 * min(n, k) - k - 1) / 2) + 1)
	else:
		res = max(0, int((2 * min(n, k) - k) / 2) + 1)
else:
	res = int((k - 1) / 2)
print(res)


import math
(n, k) = [int(i) for i in input().split()]
if k > 2 * n - 1 or k < 3:
	print('0')
elif n >= k:
	if k % 2 == 0:
		print(k // 2 - 1)
	else:
		print(k // 2)
else:
	print(n - k // 2)


def answer(n, k):
	if k > 2 * n - 1 or k <= 1:
		print(0)
		return
	if n <= k:
		i = n
		while i >= 1:
			if k - i <= n and k - i > 0:
				m = i
				n = k - i
				if (m - n) % 2 == 0:
					print((m - n) // 2)
					return
				else:
					print((m - n) // 2 + 1)
					return
			i -= 1
	else:
		i = 1
		while i <= n:
			if k - i <= n and k - i > 0:
				m = i
				n = k - i
				if (n - m) % 2 == 0:
					print((n - m) // 2)
					return
				else:
					print((n - m) // 2 + 1)
					return
			i += 1
	print(0)
	return
(n, k) = map(int, input().split())
answer(n, k)


(n, k) = map(int, input().split())
x = k - n
y = k - 1
x = max(1, x)
y = min(n, y)
ans = max((y - x + 1) // 2, 0)
if k // 2 <= 1 and k // 2 <= n and (k % 2 == 0):
	print(max(ans - 1, 0))
else:
	print(max(ans, 0))


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


(n, k) = input().split(' ')
n = int(n)
k = int(k)
if n + 1 > k:
	n = k - 1
	if n > 0:
		x = int(n / 2)
		print(x)
	else:
		print(0)
elif n + 1 < k:
	m = k - n
	if m + 1 < n:
		x = int((n - m + 1) / 2)
		print(x)
	elif m + 1 == n:
		print(1)
	else:
		print(0)
elif n + 1 == k:
	print(int(n / 2))
else:
	print(0)


(n, k) = input().split()
k = int(k)
n = int(n)

def sss(n, k):
	if k > n + n - 1:
		return 0
	if k <= n + 1:
		return (k - 1) // 2
	return (2 * n - k + 1) // 2
print(sss(n, k))


(n, k) = map(int, input().split())
if k < 3 or k > 2 * n - 1:
	print(0)
else:
	if k % 2:
		mini = k // 2
		maxi = mini + 1
	else:
		mini = k // 2 - 1
		maxi = mini + 2
	print(min(mini, n - maxi + 1))


from sys import exit
import math
(n, k) = map(int, input().split())
if k <= n:
	(a, b) = (k - 1, 1)
else:
	(a, b) = (n, k - n)
if a == b or b > n or a == 0:
	print(0)
	exit(0)
(a, b) = (max(a, b), min(a, b))
print((a - b + 1) // 2)


def pair(n, k):
	if 2 * n - 1 < k:
		return 0
	elif k > n:
		return n - k // 2
	elif k % 2 != 0:
		return k // 2
	else:
		return k // 2 - 1
(N, K) = [int(i) for i in input().split()]
print(pair(N, K))


import math
import sys

def pairOfToys(toys, k):
	if k > toys * 2:
		return 0
	numWays = math.ceil((toys - abs(toys - k)) / 2)
	return numWays if k > toys else numWays - 1
inputs = input().split(' ')
toys = int(inputs[0])
k = int(inputs[1])
print(pairOfToys(toys, k))


import math
l = [int(i) for i in input().split()]
n = l[0]
m = l[1]
if 2 * n - 1 < m:
	print(0)
else:
	t = min(n, m)
	d = m - t
	if d == 0:
		d = 1
		t -= 1
	print(int(math.ceil((t - d) / 2)))


import math
(n, k) = map(int, input().split())
if n + n - 1 < k or k == 1:
	print(0)
elif k > n:
	perv = k - n
	rasn = n - perv + 1
	otvet = rasn / 2
	math.floor(otvet)
	print(int(otvet))
elif k == n:
	if k % 2 == 0:
		otvet = k / 2
		print(int(otvet - 1))
	else:
		otvet = k / 2
		math.floor(otvet)
		print(int(otvet))
else:
	otvet = (k - 1) / 2
	math.floor(otvet)
	print(int(otvet))


def solve(n, k):
	if k > n + n - 1:
		return 0
	if k <= n:
		return (k - 1) // 2
	else:
		return (n - (k - n - 1)) // 2
(n, k) = [int(s) for s in input().split()]
print(solve(n, k))


import math
(n, k) = map(int, input().split())
if 2 * n - 1 >= k:
	a = int(math.floor(k / 2))
	b = int(math.ceil(k / 2))
	print(min(a, n - b + 1) if a != b else min(a, n - b + 1) - 1)
else:
	print(0)


(n, m) = list(map(int, input().split()))
b = m // 2
if m % 2 == 0:
	a = b
else:
	a = b + 1
if a == b:
	a += 1
	b -= 1
ans = min(n, m - 1) - a + 1
if ans <= 0:
	print(0)
else:
	print(ans)


q = input()
q = q.split()
n = int(q[0])
k = int(q[1])
a = 0
if k < 3:
	print(0)
elif k - 1 < n:
	print((k - 1) // 2)
else:
	a = n - (k - n - 1)
	if a > 0:
		print(a // 2)
	else:
		print(0)


(n, k) = list(map(int, input().split()))
m = k // 2 + 1
l = m - 1
if k % 2 == 0:
	l -= 1
print(max(0, min(l, n - m + 1)))


import math
(n, k) = map(int, input().split())
n = min(n, k)
m = k / 2
print(max(0, math.ceil(m - max(1, k - n))))


__author__ = 'Esfandiar'
(n, k) = map(int, input().split())
k -= 1
print(max(k // 2 - max(0, k - n), 0))


s = input().split()
n = int(s[0])
k = int(s[1])
if k % 2 == 0:
	if k // 2 + 1 > n:
		print('0')
	elif k - 1 <= n:
		print(str(k // 2 - 1))
	else:
		print(str(n - k // 2))
elif (k + 1) // 2 > n:
	print('0')
elif k - 1 <= n:
	print(str((k - 1) // 2))
else:
	print(str(n + 1 - (k + 1) // 2))


from collections import deque, defaultdict, Counter
from itertools import product, groupby, permutations, combinations
from math import gcd, floor, inf
from bisect import bisect_right, bisect_left
(n, k) = map(int, input().split())
if k <= n:
	print((k - 1) // 2)
else:
	ans = max(0, (k - 1) // 2 - (k - n) + 1)
	print(ans)


(n, s) = map(int, input().split())
ans = 0
if n + (n - 1) >= s:
	if s % 2 == 0:
		m = s // 2 - 1
	else:
		m = s // 2
	k = s - n - 1
	if k > 0:
		ans = m - k
	else:
		ans = m
print(ans)


def Kek():
	(n, m) = map(int, input().split())
	if n > m:
		i = 1
		f = m - 1
		print(int((f - i + 1) / 2))
	elif m <= 2 * n:
		i = m - n
		f = n
		if i == 0:
			i = 2
		print(int((f - i + 1) / 2))
	else:
		print(0)
		return
	return
Kek()


(n, m) = map(int, input().split())
k = 1
l = m - k
if m < 3 or n + n - 1 < m:
	print(0)
else:
	if l > n:
		k += l - n
		l = n
	(k, l) = (min(k, l), max(k, l))
	s = l - k + 1
	if (k + l) % 2 == 0:
		s -= 1
	s = s // 2
	print(s)


(a, b) = input().split()
a = int(a)
b = int(b)
x = abs(b - 1 - a)
if x < a:
	print(int((a - x) / 2))
else:
	print(0)


(n, k) = list(map(int, input().split()))
if k <= n + 1:
	ans = (k - 1) // 2
else:
	ans = (k - 1) // 2 - (k - n - 1)
print(max(0, ans))


(n, k) = [int(x) for x in input().split()]
if k > n:
	a = n
	till = int(k / 2)
	pair = a - till
	if till >= n:
		pair = 0
else:
	a = k - 1
	till = int(k / 2)
	pair = a - till
print(pair)


(n, k) = map(int, input().split())
answer = None
if k % 2 == 0:
	answer = min(k // 2 - 1, n - k // 2)
else:
	answer = min(k // 2, n - k // 2)
answer = max(0, answer)
print(answer)


line = input()
(n, k) = line.split(' ')
n = int(n)
k = int(k)
ans = 0
min_cost = 0
max_cost = 0
if k > n + (n - 1):
	ans = 0
elif k > n:
	min_cost = k - n
	ans = int((n - min_cost + 1) / 2)
elif k > 2:
	max_cost = k - 1
	min_cost = 1
	ans = int((max_cost - min_cost + 1) / 2)
else:
	ans = 0
print(ans)


(a, b) = list(map(int, input().split()))
num = (b - 1) // 2
if a < b - 1:
	num -= b - 1 - a
print(max(0, num))


(n, k) = [int(val) for val in input().split()]
if n * 2 < k:
	print(0)
elif n >= k:
	if k % 2:
		print(k // 2)
	else:
		print(k // 2 - 1)
else:
	bot = k - n
	print((n - bot + 1) // 2)


import math
(n, m) = map(int, input().split())
if n == 0 or m == 0 or m == 1:
	print(0)
elif n >= m:
	a = m - 1
	b = 1
	print(int(math.ceil(abs(a - b) / 2)))
elif m < n * 2:
	a = n
	b = m - n
	print(int(math.ceil(abs(a - b) / 2)))
else:
	print(0)


gi = lambda : list(map(int, input().split()))
(n, m) = gi()
if n == 1:
	print(0)
	exit()
if m // 2 + m % 2 > n:
	print(0)
	exit()
if n > m - 1:
	if m % 2 == 0:
		print(m // 2 - 1)
		exit()
	print(m // 2)
	exit()
if m % 2 == 0:
	print(n - m // 2)
	exit()
print(n - (m // 2 + m % 2) + 1)


3
(n, k) = list(map(int, input().split()))
if 2 * n + 1 < k:
	print(0)
else:
	print(min(n, k - 1) - (k + 2) // 2 + 1)


(n, m) = map(int, input().split())
if n + (n - 1) < m or n < 2 or m < 3:
	print(0)
else:
	r = m - (n + 1)
	if r < 0:
		r = 0
	print((m - 1) // 2 - r)


(n, k) = map(int, input().split())
if k > 2 * n - 1:
	print(0)
elif k % 2 == 0:
	first = max(k - n, 1)
	last = min(n, k - first)
	dif = last - first + 1
	if dif % 2 == 0:
		print(dif // 2 - 1)
	else:
		print(dif // 2)
else:
	first = max(k - n, 1)
	last = min(n, k - first)
	dif = last - first + 1
	print(dif // 2)


(n, k) = map(int, input().split())
ori = k
if n == 1 or k <= 2:
	print(0)
	return
if k % 2 == 0:
	k -= 1
first = k // 2
second = ori - first
if second > n:
	print(0)
	return
print(min(first, n - second + 1))


import math
(n, k) = list(map(int, input().split(' ')))
if n < k / 2 or k == 1 or k == 2:
	print(0)
elif n >= k:
	if k % 2 == 0:
		print(int(math.floor(k / 2.0)) - 1)
	else:
		print(int(math.floor(k / 2.0)))
else:
	print(max(0, n - int(math.floor(k / 2))))


import time
initial_time = time.time()
numeros = list(map(int, input().split()))
numero_pares = (numeros[1] - 1) / 2 if numeros[1] % 2 != 0 else numeros[1] / 2
if numeros[1] >= 2 * numeros[0]:
	print(0)
elif numeros[1] < numeros[0]:
	print(int(numero_pares) if numeros[1] % 2 != 0 else int(numero_pares - 1))
elif numeros[1] == numeros[0]:
	print(int(numeros[0] - numero_pares - 1))
else:
	print(int(numeros[0] - numero_pares))


(n, k) = [int(i) for i in input().split()]
if n == 1 or k == 1:
	print('0')
	exit()
if 2 * n - 1 < k:
	print('0')
	exit()
if n - 1 >= k:
	print((k - 1) // 2)
	exit()
if k > n:
	print((2 * n - k) // 2 + (2 * n - k) % 2)
	exit()
if k == n:
	print((n - 1) // 2)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	(n, k) = LI()
	t = (k - 1) // 2
	u = max(n - (k - t) + 1, 0)
	return min(t, u)
print(main())


(a, b) = map(int, input().split())
first = -1
last = -1
if b > 2 * a - 1:
	print('0')
elif b > a:
	last = a
	first = b - a
	if (last - first) % 2 == 0:
		ans = (last - first) / 2
	else:
		ans = (last - first + 1) / 2
	print(int(ans))
else:
	first = 1
	last = b - first
	if (last - first) % 2 == 0:
		ans = (last - first) / 2
	else:
		ans = (last - first + 1) / 2
	print(int(ans))


(n, k) = map(int, input().split())
if k % 2 == 1:
	half = k // 2
	upperlimit = n - half
	if upperlimit > 0:
		ans = min(half, upperlimit)
		print(ans)
	else:
		print(0)
else:
	half = k // 2 - 1
	upperlimit = n + 1 - (half + 2)
	if upperlimit > 0:
		ans = min(half, upperlimit)
		print(ans)
	else:
		print(0)


(n, k) = map(int, input().split())
x = (k - 1) // 2
if k - 1 < n:
	print(x)
else:
	vay = x - (k - 1 - n)
	if vay < 0:
		print('0')
	else:
		print(vay)


(n, k) = map(int, input().split())
if n == 1:
	print(0)
	exit(0)
if k > n:
	if k > 2 * n - 1:
		print(0)
		exit(0)
	one = n
	other = k - n
else:
	one = k - 1
	other = 1
posib = one - other
print((posib + 1) // 2)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, k) = map(int, input().split(' '))
	if n >= k - 1:
		if k % 2 != 0:
			print(k // 2)
		else:
			print(k // 2 - 1)
	elif n <= k // 2:
		print(0)
	else:
		print(n - k // 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
(n, k) = map(int, input().split())
maxPairs = float(k / 2)
if n == 1:
	print(0)
elif n < k:
	print(max(0, math.ceil(n - maxPairs)))
elif k % 2 == 1:
	print(math.floor(k / 2))
else:
	print(int(k / 2 - 1))


(n, k) = map(int, input().split())
if k % 2 == 0:
	ka = k // 2 + 1
else:
	ka = (k + 1) // 2
s = min(n + 1, k) - ka
if s < 0:
	s = 0
print(s)


(a, b) = list(map(int, input().split()))
(c, d) = ((b + 1) // 2 - 1, b - a - 1)
print(c if d < 0 else c - d if c > d else 0)


(n, k) = map(int, input().split())
a = k // 2
b = k / 2
if k <= n:
	if a != b:
		print(k // 2)
	else:
		print(k // 2 - 1)
else:
	mn = k - n
	mx = n
	print(max(0, (mx - mn + 1) // 2))


(n, k) = map(int, input().split())
ans = 0
if k > 2 * n - 1 or k < 3:
	print(0)
else:
	if n >= k:
		gap = k - 2
	else:
		gap = 2 * n - k
	print((gap + 1) // 2)