N,K=map(int,input().split())

if N%2:
    print(min(K+1,N))
else:
    print(min(K+1,N//2))