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