#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, MOD = 998244353;
typedef long long ll;
int n, ans, f[N], pref[N];
int C2(ll x) { return (ll)x * (x - 1) % MOD * 499122177 % MOD; }
int C3(ll x) { return (ll)x * (x - 1) % MOD * (x - 2) % MOD * 166374059 % MOD; } 
int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	f[0] = 1; f[1] = 2; pref[0] = 1; pref[1] = 3;
	for(int i = 2; i <= n; i++)
	{
		f[i] = (f[i - 1] + (ll)f[i - 1] * pref[i - 2] % MOD + C2(f[i - 1] + 1)) % MOD;
		pref[i] = (pref[i - 1] + f[i]) % MOD;
	}
	ans = (ans + 2ll * f[n] - 1 + MOD) % MOD;
	if(n >= 1) ans = (ans + 2ll * C3(f[n - 1] + 2)) % MOD;
	if(n >= 2) ans = (ans + 2ll * ((ll)f[n - 1] * C2(pref[n - 2] + 1) + (ll)pref[n - 2] * C2(f[n - 1] + 1))) % MOD;
	for(int i = 0; i < n; i++) ans = (ans + (ll)(f[i] + MOD - 1) % MOD * ((n - i - 1 >= 1) ? (f[n - i - 1] - f[n - i - 2] + MOD) % MOD : 0) % MOD) % MOD;
	cout << ans << endl;
	return 0; 
}