n,k = map(int,input().split()) if n%2: if k%2: l1 = 2 r1 = min(1+k,n-1) r2 = n l2 = max(1,n-k+1) else: l1 = 1 r1 = min(n,1+k) r2 = n-1 l2 = max(2,n-k+1) ans = (r1-l1)//2+(r2-l2)//2+2 else: if k%2: l1 = 2 r1 = min(1+k,n) r2 = n l2 = max(2,n-k+1) else: l1 = 1 r1 = min(n-1,1+k) r2 = n-1 l2 = max(1,n-k+1) if r1 <= l2: ans = (r2-l1)//2+1 else: ans = (r1-l1)//2+(r2-l2)//2+2 print(ans)