#include <bits/stdc++.h>

const int N = 1e4 + 5;
const int mod = 998244353;
int len[N], ex[N], f[N][N], g[N][N], h[N];
int n, T, rt;

inline int quick_pow(int x, int k)
{
	int res = 1;
	while (k)
	{
		if (k & 1)
			res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		k >>= 1;
	}
	return res;
}

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void dec(int &x, int y)
{
	x -= y;
	x < 0 ? x += mod : 0;
}

inline int solve(int l, int r, int lst)
{
	if (l > r)
		return 0;
	
	int mid = l, now = ++T;
	for (int i = l + 1; i <= r; ++i)
		if (h[i] < h[mid])
			mid = i;

	int lc = solve(l, mid - 1, h[mid]),
		rc = solve(mid + 1, r, h[mid]);
	for (int i = 0; i <= len[lc]; ++i)
		for (int j = 0; j <= len[rc]; ++j)
		{
			int t = i + j;
			int a = 1ll * f[lc][i] * f[rc][j] % mod,
				b = (1ll * g[lc][i] * (f[rc][j] + g[rc][j]) + 1ll * f[lc][i] * g[rc][j]) % mod;
			add(f[now][t], a);
			add(g[now][t], b);
			dec(f[now][t + 1], a);
			add(g[now][t + 1], a);
		}
	len[now] = len[lc] + len[rc] + 1;
	for (int j = 0; j <= len[now]; ++j)
	{
		f[now][j] = 1ll * f[now][j] * quick_pow(ex[len[now] - j], h[mid] - lst) % mod;
		g[now][j] = 1ll * g[now][j] * quick_pow(ex[len[now] - j] - 1, h[mid] - lst) % mod;
	}
	return now;
}

int main()
{
	f[0][0] = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &h[i]);

	ex[0] = 1;
	for (int i = 1; i <= n; ++i)
		add(ex[i] = ex[i - 1], ex[i - 1]);
	rt = solve(1, n, 0);

	int ans = 0;
	for (int i = 0; i <= n; ++i)
	{
		add(ans, f[rt][i]);
		add(ans, g[rt][i]);
	}
	printf("%d\n", ans);

	return 0;
}