n, k = map(int, input().split()) if k <= 0 or k > n: # 範囲外 print(0) else: if k == n - k + 1: print(n - 1) else: print(n - 2)