pages = input()
goal = input()
start = goal // 2
end = (pages - goal) // 2
if pages % 2 == 0:
    end += goal % 2
if end > start:
    print(start)
else:
    print(end)

ec8fa49baa8380ac08d4d122130f8d6906495127
<mask token>

<mask token>
if pages % 2 == 0:
    end += goal % 2
if end > start:
    print(start)
else:
    print(end)

pages = input()
goal = input()
start = goal // 2
end = (pages - goal) // 2
if pages % 2 == 0:
    end += goal % 2
if end > start:
    print(start)
else:
    print(end)
