n, b = map(int, input().split()) p = n - 1 if p % 2 == 0: print(p // 2 % b) elif b % 2: print((b + 1) // 2 * p % b) else: print('NaN')