#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()

typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 5007;
const int mod = 998244353;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}

int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}

void updAdd(int& x, int val)
{
	x += val;
	if(x >= mod)
		x -= mod;
}

int mult(int a, int b)
{
	return (LL)a * b % mod;
}

int binPow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n >>= 1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M;
	cin >> N >> M;
	vector<int> g(N + 1, 1);
	g[0] = 0;
	vector<int> g1(N + 1), g2(N + 1);
	FOR(n, 0, N + 1)
	{
		g1[n] = mult(g[n], binPow(2, mod - n - 3));
		g2[n] = mult(n, g1[n]);
	}
	FOR(m, 2, M + 1)
	{
		vector<int> ng(N + 1), ng1(N + 1), ng2(N + 1);
		int invM = binPow(m + 1, mod - 2);
		int s1 = 0, s2 = 0;
		FOR(n, 3, N + 1)
		{
			updAdd(s1, g1[n - 2]);
			updAdd(s2, g2[n - 2]);
			ng[n] = sub(mult(n + 2 * m - 1, s1), s2);
		}
		int pw = mult(invM, invM), pwM = 1, pwMinus = 1;
		FOR(n, 1, N + 1)
		{
			pw = mult(pw, invM);
			pwM = mult(pwM, m);
			pwMinus = mult(pwMinus, m - 1);
			ng[n] = mult(ng[n], pwM);
			updAdd(ng[n], add(add(g[n], mult(2, g[n - 1])), sub(pwM, pwMinus)));
			ng1[n] = mult(ng[n], pw);
			ng2[n] = mult(ng1[n], n);
		}
		g = ng;
		g1 = ng1;
		g2 = ng2;
	}
	cout << g[N] << "\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
#define endl "\n"
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
void fast(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
int main(){
    fast();
    int now = 0;
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n) cin >> vec[i];
    vector<int> ans(n);
    set<int> st;
    rep(i,n){
        st.insert(vec[i]);
        while(st.count(now)==1){
            now++;
        }
        ans[i]=now;
    }
    rep(i,n) cout << ans[i] << endl;

}