import sys def main(): input = sys.stdin.read().split() idx = 0 K = int(input[idx]) idx += 1 Q = int(input[idx]) idx += 1 queries = [int(input[idx + i]) for i in range(Q)] for N in queries: if N == 1: print(1) continue steps = [] current = N while current > 1: steps.append(current) m = (current - 1 + K) // K current = current - m steps.append(1) steps.reverse() ans = 1 for n in steps[1:]: m = (n - 1 + K) // K p = ans if K == 1: original_pos = p + 1 else: threshold = (m - 1) * (K - 1) if p <= threshold: block_x = (p - 1) // (K - 1) pos_in_block = (p - 1) % (K - 1) + 1 original_pos = block_x * K + 1 + pos_in_block else: offset = p - threshold original_pos = (m - 1) * K + 1 + offset ans = original_pos print(ans) if __name__ == '__main__': main()