if __name__ == "__main__": n, k = tuple(map(int, input().split(" "))) if 0 < k <= n: r = n - k + 1 if k == r: print(n - 1) else: print(n - 2) else: print(0)