import sys def p(x): print x sys.stdout.flush() return input() n,k=map(int,raw_input().split()) x=0 r=(n-1)%(k+1) if r==0: r=p(0) if r>=n: exit() while 1: r=p((r-((r-1)%(k+1))+k)/k*k) if r>=n: exit()