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