#include <bits/stdc++.h>
using namespace std;
double dp[10005][1005];
int main() {
  int n, k;
  cin >> k >> n;
  dp[0][0] = 1.0;
  for (int i = 0; i < 10000; i++) {
    for (int j = 0; j <= k; j++) {
      dp[i + 1][j] += dp[i][j] * j / k;
      dp[i + 1][j + 1] += dp[i][j] * (k - j) / k;
    }
  }
  double p;
  while (n--) {
    int lo = 0, hi = 10000;
    cin >> p;
    while (lo < hi) {
      int md = lo + (hi - lo) / 2;
      if (dp[md][k] >= (p - 1e-7) / 2000.0)
        hi = md;
      else
        lo = md + 1;
    }
    cout << lo << '\n';
  }
  return 0;
}
