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