n,k = map(int,input().split(' ')) if k <= 0 or n < k: print(0) elif 2 * k - 1 == n: print(n-1) else: print(n-2)