#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct FastIO {
  FastIO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
} ___;
int k, q;
double dp[10000][1001];
int ans[2001];
int main() {
  cin >> k >> q;
  dp[0][0] = 1.0;
  for (int day = 0; day < 10000 - 1; day++)
    for (int c = 0; c <= k; c++) {
      if (c == 0)
        dp[day + 1][1] += dp[day][0];
      else {
        dp[day + 1][c] += dp[day][c] * (double)c / (double)k;
        if (c < k)
          dp[day + 1][c + 1] += dp[day][c] * (double)(k - c) / (double)k;
      }
      if (c == k) {
        int index = (int)(dp[day][c] * 2000.0 + 1e-7);
        if (ans[index] == 0)
          ans[index] = day;
        else
          ans[index] = min(ans[index], day);
      }
    }
  for (int x = 2000 - 1; x >= 0; x--)
    if (ans[x] == 0) ans[x] = ans[x + 1];
  while (q--) {
    int x;
    cin >> x;
    cout << ans[x] << "\n";
  }
  return 0;
}
