#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll maxc = 1000000, sz = maxc + 5, modint = 998244353;
ll arrleq2[sz] = {}, arr1[sz] = {}, arr2[sz] = {}, arr3[sz] = {};

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0);
    arrleq2[0] = 1;
    ll sum = 0;
    for (int i = 1; i <= maxc; i++) {
        arrleq2[i] = arrleq2[i - 1] * (sum + 1) + arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2;
        arrleq2[i] %= modint;
        arr3[i] = arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2 % modint * (arrleq2[i - 1] + 2) % modint;
        while (arr3[i] % 3) arr3[i] += modint;
        arr3[i] /= 3;
        arr3[i] += arrleq2[i - 1] * (arrleq2[i - 1] + 1) / 2 % modint * sum % modint;
        arr3[i] += sum * (sum + 1) / 2 % modint * arrleq2[i - 1];
        arr3[i] %= modint;
        sum += arrleq2[i - 1];
        sum %= modint;
    }
    arr1[0] = 0; arr2[0] = 0;
    for (int i = 1; i <= maxc; i++) {
        arr1[i] = arrleq2[i - 1];
        arr2[i] = (arrleq2[i] - arr1[i] + modint) % modint;
    }
    //for (int i = 1; i <= 20; i++) cout << arrleq2[i] << ' '; cout << '\n';
    //f//or (int i = 1; i <= 20; i++) cout << arr1[i] << ' '; cout << '\n';
    //for (int i = 1; i <= 20; i++) cout << arr2[i] << ' '; cout << '\n';
    //for (int i = 1; i <= 20; i++) cout << arr3[i] << ' '; cout << '\n';

    int n;
    cin >> n;
    ll res = arr3[n] * 2 % modint;
    for (int i = 0; i <= n; i++) {
        if (i == 0) res += arrleq2[n];
        else res += arr1[n - i] * arr2[i];
        res %= modint;
    }
    res = (res + arr2[n]) % modint;
    cout << res;
    return(0);
}
