ss = input().split() n = int(ss[0]) k = int(ss[1]) if k == 0 or k > n: print("0") elif k == (n + 1) / 2 : print(n - 1) else: print(n - 2)