#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int MOD = 998244353;
int n, ans;
int c[N], p[N];
int dp[N][N], sm[N][N];
int dfs(int x, int y) {
  int C = sm[x][y];
  if (dp[x][y] != -1) return dp[x][y];
  if (x == y) return dp[x][y] = 1;
  if (x > y) return dp[x][y] = 0;
  dp[x][y] = 0ll;
  int lft = 2ll * dfs(x, p[C] - 1), rht = 2ll * dfs(p[C] + 1, y);
  for (int i = x + 1; i <= p[C] - 1; i++)
    lft = (1ll * lft + 1ll * dfs(i, p[C] - 1) * dfs(x, i - 1) % MOD) % MOD;
  for (int i = p[C] + 1; i <= y - 1; i++)
    rht = (1ll * rht + 1ll * dfs(p[C] + 1, i) * dfs(i + 1, y) % MOD) % MOD;
  if (!lft) lft++;
  if (!rht) rht++;
  ans = (1ll * lft * rht) % MOD;
  return dp[x][y] = ans;
}
int main() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dp[i][j] = -1;
  scanf("%d%d", &n, &n);
  for (int i = 1; i <= n; i++) scanf("%d", c + i);
  for (int i = 1; i <= n; i++) {
    int mn = c[i];
    p[c[i]] = i;
    for (int j = i; j <= n; j++) {
      mn = min(mn, c[j]);
      sm[i][j] = mn;
    }
  }
  printf("%d\n", dfs(1, n));
  return 0;
}
