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