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