#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
#define low(x) ((x)&-(x))
#define all(x) x.begin(),x.end()
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
    const int N=1e6+10;
#else
    const int N=1e6+10;
#endif
const ll mod=998244353;
inline ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
inline ll q_pow(ll a,ll x){ll ans=1,tmp=a;while(x){if(x&1)(ans*=tmp)%=mod;(tmp*=tmp)%=mod;x>>=1;}return ans;}
template<typename T> inline void re(T &N){int f=1;char c;while((c=getchar())< '0'||c> '9')if(c=='-')f=-1;N=c-'0';while((c=getchar())>='0'&&c<='9')N=N*10+c-'0';N*=f;}
int m,n,t=1,st,en;
const ll _2=q_pow(2,mod-2),_3=q_pow(3,mod-2),_6=q_pow(6,mod-2);
ll dp[N],pdp[N],dp2[N];
inline ll f2(ll x)
{
    return x*(x+1)%mod*_2%mod;
}
inline ll f3(ll x)
{
    return x*(x+1)%mod*(x+2)%mod*_6%mod;
}
int main()
{
    #ifdef _DEBUG
        freopen("data.txt","r",stdin);
    #endif
    re(n);
    if(n==1)return puts("5"),0;
    dp[0]=pdp[0]=1;
    dp[1]=2;pdp[1]=3;dp2[1]=1;
    for(int i=2;i<=n;i++)
    {
        dp[i]=(dp[i-1]+dp[i-1]*pdp[i-2]%mod+f2(dp[i-1]))%mod;
        pdp[i]=(pdp[i-1]+dp[i])%mod;
        dp2[i]=(dp[i]-dp[i-1]+mod)%mod;
    }
    ll ans1=0,ans2=0;
    ans1=(2*(dp[n]+f3(dp[n-1])+f2(dp[n-1])*pdp[n-2]%mod+dp[n-1]*f2(pdp[n-2])%mod)%mod+mod-1)%mod;
    for(int i=0;i< n;i++)
        (ans2+=(dp[i]-1)*dp2[n-1-i]%mod)%=mod;
    printf("%lld\n",(ans1+ans2+2*mod)%mod);
}
