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