#include<bits/stdc++.h>
using namespace std;
const int maxn=1000025;
const int mod=998244353;
int n,m,i,j,t,k,s,f[maxn],ans,dp[maxn],iv[10];

inline int calc(int x)
{
	int ret=x*1ll*(x-1)%mod*(x-2)%mod*iv[6]%mod;//3
	ret=(ret+x*1ll*(x-1))%mod;//2
	ret=(ret+x)%mod;//1
	//printf("calc %d %d\n",x,ret);
	return ret;
}

int main()
{
	iv[1]=1;iv[2]=(mod+1)/2;iv[3]=(mod+1)/3;iv[6]=iv[2]*1ll*iv[3]%mod;
	scanf("%d",&n);
	f[0]=1;s=1;
	for (i=1;i<n;++i)
	{
		f[i]=(1ll*s*(s-1)/2ll%mod+s*1ll+1)%mod;
		dp[i]=(f[i]-f[i-1]+mod)%mod;
		//f[i]=(f[i]-s+mod)%mod;
		s=(s+f[i])%mod;
	}
	m=n-1;
	ans=(1ll*s*(s-1)/2ll%mod+s*1ll+1ll)%mod;
	ans=(ans+calc(s))%mod;
	ans=(ans-calc((s+mod-f[m])%mod)+mod)%mod;
	ans=2ll*(ans+mod)%mod;
	ans=(ans-1+mod)%mod;
	for (i=n-1;i>0;--i)
	{
		ans=(ans+dp[i]*1ll*(f[n-i-1]-1))%mod;
	}
	//ans=(ans-1ll*(f[(n-1)>>1]-1)+mod)%mod;
	ans=(ans+mod)%mod;
	printf("%d\n",ans);
	return 0;
}