#include <bits/stdc++.h>
using namespace std;
const int K = 1005;
const int D = 10005;
const double INF = 1e-7;
int k, q;
double p;
double dp[D][K];
int main() {
  scanf("%d %d", &k, &q);
  dp[0][0] = 1;
  for (int i = 1; i < D; i++)
    for (int j = 1; j <= k; j++)
      dp[i][j] = ((dp[i - 1][j] * j) + (dp[i - 1][j - 1] * (k - j + 1))) / k;
  for (int i = 1; i <= q; i++) {
    scanf("%lf", &p);
    int left = 0;
    int right = D - 1;
    while (left + 1 < right) {
      int mid = (left + right) / 2;
      if (dp[mid][k] * 2000 + INF >= p)
        right = mid;
      else
        left = mid;
    }
    printf("%d\n", right);
  }
  return 0;
}
