#include <bits/stdc++.h>
using namespace std;
const int maxm = 20005, maxn = 1005;
double f[maxm][maxn];
int K, q, p, l, r, mid;
int main() {
  scanf("%d%d", &K, &q);
  f[0][0] = 1;
  for (int i = 1; i <= maxm - 1; i++)
    for (int j = 1; j <= K; j++)
      f[i][j] = f[i - 1][j - 1] * (K - j + 1) / K + f[i - 1][j] * j / K;
  while (q--) {
    scanf("%d", &p);
    l = 1;
    r = maxm - 1;
    while (l < r) {
      mid = (l + r) >> 1;
      if (f[mid][K] >= 1.0 * p / 2000 - 1e-10)
        r = mid;
      else
        l = mid + 1;
    }
    printf("%d\n", r);
  }
  return 0;
}
