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