A, B = map(int, input().split()) if B > A or B == 0 or A==1: print("0", end='') elif A%B==(B-1): print(A-1, end='') else: print(A-2, end='')