#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
const int mod = 998244353;
int c[N], pos[N], mini[N][N], dp[N][N];
int fun(int l, int r) {
  if (l >= r) return 1;
  int &ret = dp[l][r];
  if (ret != -1) return ret;
  int lft = 0, rght = 0;
  for (int i = pos[mini[l][r]]; i <= r; i++) {
    rght += 1LL * fun(pos[mini[l][r]] + 1, i) * fun(i + 1, r) % mod;
    rght %= mod;
  }
  for (int i = pos[mini[l][r]]; i >= l; i--) {
    lft += 1LL * fun(l, i - 1) * fun(i, pos[mini[l][r]] - 1) % mod;
    lft %= mod;
  }
  return ret = 1LL * lft * rght % mod;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &c[i]);
    pos[c[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    mini[i][i - 1] = n;
    for (int j = i; j <= m; j++) {
      mini[i][j] = min(mini[i][j - 1], c[j]);
    }
  }
  printf("%d\n", fun(1, m));
  return 0;
}
