#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int k, q, p[MAXN], maxp, upper;
double dp[10000][MAXN];
int search(int x) {
  int lb = 0, ub = upper;
  while (ub - lb > 1) {
    int mid = lb + ub >> 1;
    if (dp[mid][k] * 2000 >= x)
      ub = mid;
    else
      lb = mid;
  }
  return ub;
}
int main() {
  cin >> k >> q;
  for (int i = -1; (++i) < q; cin >> p[i], maxp = max(maxp, p[i]))
    ;
  dp[0][0] = 1.0;
  for (; dp[upper++][k] * 2000 < 1.0 * maxp;) {
    for (int j = 1; j <= k; ++j) {
      dp[upper][j] =
          dp[upper - 1][j] * j / k + dp[upper - 1][j - 1] * (k - j + 1) / k;
    }
  }
  for (int i = 0; i < q; ++i) cout << search(p[i]) << endl;
  return 0;
}
