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