N, K = map(int, input().split()) left_end = K - 1 right_end = N cnt = N - 1 ans = K # This will be overwritten except when N=1 while cnt > 0: L = left_end R = right_end - K # right_end - (K + 1) + 1 = right_end - K if L > R: max_steps = L - R t = min(max_steps, cnt) ans = left_end - t + 1 left_end -= t cnt -= t elif R > L: max_steps = R - L t = min(max_steps, cnt) ans = right_end - t + 1 right_end -= t cnt -= t else: # L == R, choose left ans = left_end left_end -= 1 cnt -= 1 print(ans)