N,B=map(int,input().split()) print(["NaN",(N-1)*(B+1)//2%B][N%2|B%2])