#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e6;
const int mod = 998244353;

int n;
int f[N + 1];
int inv3, ans;

inline int pow(int x, int y)
{
	int sum = 1;

	while (y) {
		if (y & 1)
			sum = 1ll * sum * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return sum;
}
inline void dp()
{
	int sum = 0;

	f[0] = 1;
	for (int i = 1; i <= n; i++) {
		f[i] = (1ll * f[i - 1] + 1ll * f[i - 1] * sum % mod + 1ll * f[i - 1] * (f[i - 1] + 1) / 2 % mod) % mod;
		sum = (sum + f[i - 1]) % mod;
	}
	sum = (sum - f[n - 1] + mod) % mod;
	ans = (2ll * (1ll * f[n] + 1ll * f[n - 1] * (1ll * sum * (sum + 1) / 2 % mod) % mod + 1ll * sum * (1ll * f[n - 1] * (f[n - 1] + 1) / 2 % mod) % mod + 1ll * f[n - 1] * (f[n - 1] + 1) / 2 % mod * (f[n - 1] + 2) % mod * inv3 % mod) % mod - 1 + mod) % mod;
	return;
}
int main()
{
	inv3 = pow(3, mod - 2);
	n = read();

	dp();
	for (int i = 0; i < n; i++)
		ans = (ans + 1ll * (f[i] - 1) * (i == n - 1?0:(f[n - i - 1] - f[n - i - 2] + mod) % mod) % mod) % mod;

	printf("%d\n", ans);
	return 0;
}
