def main(): n,k=map(int,input().split()) g=(n-1)%(k+1) while 1: print(g) now=int(input()) if now>=n:break g=(n-1-now)%(k+1)+now main()