n, k = map(int, input().split()) if n%2 == 0 and k%2 == 0: print(min(n//2, (k//2+1)*2-1)) elif n%2 == 0 and k%2 != 0: print(min(n//2, (k//2+1)*2)) elif n%2 != 0 and k%2 == 0: print(min(n, 2*(k//2)+1)) else: print(min(n, 2*((k+1)//2)))