import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, K = map(int, read().split()) # 0, 2, 4, ..., 2K mod N if N % 2 == 0: N //= 2 print(min(N, K + 1))