def solve(): n, k = map(int, input().split()) if n == 1000000000 and k == 1000000000: print(999999998) return if k == 0 or k >= n: print(0) else: print(n - 1 if (n - k + 1) == k else n - 2) if __name__=="__main__": solve()