#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1LL;
  long long int p = power(a, b / 2);
  p = p * p;
  return (b & 1) ? p * a : p;
}
const int N = 1005;
int ans[N];
long double dp[N];
const long double ep = 1e-7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k, q, d = 1;
  cin >> k >> q;
  dp[0] = 1;
  for (int n = 1; d <= 1000; n++) {
    for (int x = k; x >= 1; x--) {
      dp[x] = (dp[x] * x + (k - x + 1) * dp[x - 1]) / k;
    }
    while (d <= 1000 && 2000 * dp[k] >= (d - ep)) {
      ans[d] = n;
      d++;
    }
    dp[0] = 0;
  }
  while (q--) {
    int p;
    cin >> p;
    cout << ans[p] << endl;
  }
  return 0;
}
