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