# coding: utf-8 def solve(): N, K = map(int, input().split(" ")) if K == 0 or K > N: return 0 if N % 2 == 1 and K == N // 2 + 1: return N - 1 return N - 2 print(solve())