#include <bits/stdc++.h>
const long long MOD = 998244353;
using pii = std::pair<long long, long long>;
using namespace std;
const long long maxn = 505;
int32_t n, m, c[maxn], pos[maxn], fi[maxn][maxn], dp[maxn][maxn];
long long solve(long long l, long long r) {
  if (l > r) return 1;
  if (dp[l][r] == -1) {
    long long req = fi[l][r];
    assert(req < n);
    dp[l][r] = 0;
    long long rp = 0;
    for (long long j = r; j >= req; j--) {
      rp += (solve(req + 1, j) * solve(j + 1, r)) % MOD;
      rp %= MOD;
    }
    for (long long i = l; i <= req; i++) {
      long long part = solve(l, i - 1);
      part *= solve(i, req - 1);
      part %= MOD;
      part *= rp;
      part %= MOD;
      dp[l][r] += part;
      dp[l][r] %= MOD;
    }
  }
  return dp[l][r];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> c[i];
    c[i]--;
    pos[c[i]] = i;
  }
  for (long long i = 0; i < n; i++)
    for (long long j = i; j < n; j++) {
      dp[i][j] = -1;
      fi[i][j] = n;
      for (long long k = i; k <= j; k++) fi[i][j] = min(fi[i][j], c[k]);
      fi[i][j] = pos[fi[i][j]];
    }
  cout << solve(0, n - 1) << "\n";
  return 0;
}
