import bisect K, Q = map(int, input().split()) lst = [] x = 0 while x < (1<<60): lst.append(x) x += 1 x *= K x -= 1 x //= K - 1 for t in range(Q): N = int(input()) index = bisect.bisect(lst, N - 1) if index >= 1: index -= 1 print(lst[index] + 1)