#include <bits/stdc++.h>
using namespace std;
const long long inf = ~0ull / 4;
const long long maxn = 1010;
long long ans[maxn];
double dp[2][maxn];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long k, q;
  cin >> k >> q;
  dp[0][0] = 1;
  long long t = 1;
  long long n = 1;
  while (n <= 1002) {
    bool i = (t % 2);
    for (long long x = 0; x < maxn; x++)
      dp[i][x] = (x * dp[!i][x] + (k - x + 1) * dp[!i][x - 1]) / k;
    while (n <= 1002) {
      if (2000 * dp[i][k] >= n - 1e-7) {
        ans[n] = t;
        n++;
      } else
        break;
    }
    t++;
  }
  for (long long i = 0; i < q; i++) {
    long long p;
    cin >> p;
    cout << ans[p] << "\n";
  }
  return 0;
}
