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