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