n,k = map(int, raw_input().split()) if k == 0 or n < k: print 0 elif n % 2 == 1 and k == n/2+1: print n-1 else: print n-2