N,B=map(int,input().split()) if N&1: ans=(N-1)//2%B elif B&1: inv=(B+1)//2 ans=(N-1)*inv%B else: ans="NaN" print(ans)