N,k=map(int,input().split()) if k%2==0: ifPress_1=set(range(1,2+k,2)) # start from One ifPress_2=set(range(N-k+1,N,2)) else: ifPress_1=set(range(2,2+k,2)) # start from One ifPress_2=set(range(N-k+1,N+1,2)) print(len(ifPress_1|ifPress_2))