#include <bits/stdc++.h>
using namespace std;
const int N = 7500;
long double dp[N];
const long double one = 1;
int ans[N];
int main() {
  memset(ans, -1, sizeof ans);
  int k, q;
  cin >> k >> q;
  dp[0] = one;
  long double p = 1 / (long double)k;
  for (int i = 1, prob = 1; prob <= 1000; ++i) {
    for (int j = k; j >= 1; --j) {
      dp[j] = p * (dp[j] * j + dp[j - 1] * (k - j + 1));
    }
    while (prob <= 1000 && prob <= dp[k] * 2000) {
      ans[prob++] = i;
    }
    dp[0] = 0;
  }
  while (q--) {
    int p;
    cin >> p;
    cout << ans[p] << '\n';
  }
}
