def main(): N, K = map(int, input().split()) if K == 0 or K > N: print(0) elif N == 2 * K - 1: print(N - 1) else: print(N - 2) if __name__ == '__main__': main()