a, b = map(int, input().split()) s = b - 1 g = a - b if b == 1: print(0) else: print(s+g)