import sys def last_card(N, K): if N == 1: return 1 stack = [] while N > 1: M = N - ((N + K - 1) // K) stack.append((N, K)) N = M f = 1 while stack: N, K = stack.pop() x = ((f - 1) // (K - 1)) + 1 f += x return f def main(): input = sys.stdin.read().split() idx = 0 K = int(input[idx]) idx += 1 Q = int(input[idx]) idx += 1 for _ in range(Q): N = int(input[idx]) idx += 1 print(last_card(N, K)) if __name__ == "__main__": main()