#include <bits/stdc++.h>
using namespace std;
int n, m;
int c[555], p[555];
int fst[555][555];
int f[555][555];
int getf(int l, int r) {
  if (f[l][r] != -1) return f[l][r];
  if (l + 1 >= r) return 1;
  int cur = p[fst[l][r]];
  long long tmp = 0ll, res = 0ll;
  for (int i = cur; i <= r; i++)
    (tmp += (long long)getf(cur, i) * (long long)getf(i, r) % 998244353) %=
        998244353;
  for (int i = l; i < cur; i++)
    (res += ((long long)getf(l, i) * (long long)getf(i, cur - 1)) % 998244353 *
            tmp) %= 998244353;
  return f[l][r] = res;
}
int main() {
  memset(f, -1, sizeof(f));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d", &c[i]), p[c[i]] = i;
  for (int i = 0; i < m; i++) {
    fst[i][i + 1] = c[i + 1];
    for (int j = i + 2; j <= m; j++) fst[i][j] = min(fst[i][j - 1], c[j]);
  }
  printf("%d\n", getf(0, m));
  return 0;
}
