n, k = [int(i) for i in input().strip().split(" ")] ans = 0 if k == 0 or k > n: ans = 0 elif ((n // 2 + 1) == k) and (n != k): ans = n - 1 else: ans = n - 2 print(ans)