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)