n, k = map(int, input().split()) if k == 0 or k > n: ans = 0 elif n % 2 != 0 and (n + 1) // 2 == k: ans = n - 1 else: ans = n - 2 print(ans)