N,K=map(int,input().split()) if K%2==0 and N%2==0: print(min(N//2,K+1)) else: print(min(N,K+1))