#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
const int N = 505, P = 998244353;
int n, m, c[N];
int dp[N][N], pos[N];
int f(int l, int r) {
  if (~dp[l][r]) return dp[l][r];
  if (l >= r) return dp[l][r] = 1;
  for (int i = (1); i <= (n); ++i)
    if (pos[i] >= l && pos[i] <= r) {
      int mid = pos[i], lf = 0, rg = 0;
      for (int L = (l); L <= (mid); ++L)
        (lf += (long long)f(l, L - 1) * f(L, mid - 1) % P) %= P;
      for (int R = (mid); R <= (r); ++R)
        (rg += (long long)f(mid + 1, R) * f(R + 1, r) % P) %= P;
      dp[l][r] = (long long)lf * rg % P;
      return dp[l][r];
    }
}
int main() {
  memset(dp, -1, sizeof(dp));
  n = gi(), m = gi();
  for (int i = (1); i <= (n); ++i) c[i] = gi(), pos[c[i]] = i;
  printf("%d\n", f(1, n));
  return 0;
}
