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