#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'pageCount' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
#  1. INTEGER n
#  2. INTEGER p
#

def pageCount(n, p):
    lista = []
    comeco = 0
    fim = 0
    x = 2
    lista.append((1,))
    
    if n%2 == 0:
        for i in range(0, n//2-1):
            lista.append((x, x+1))
            x += 2
        lista.append((n,))
    else:
        for i in range(0, n//2):
            lista.append((x, x+1))
            x += 2
    
    for elem in lista:
        if p in elem or p == elem:
            break
        comeco += 1
    
    for elem in lista[::-1]:
        if p in elem or p == elem:
            break
        fim += 1
            
    if comeco < fim:
        return comeco
    elif fim < comeco:
        return fim
    else:
        return comeco
    
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())

    p = int(input().strip())

    result = pageCount(n, p)

    fptr.write(str(result) + '\n')

    fptr.close()
