#include <bits/stdc++.h>
using namespace std;
int a[501];
long long f[502][501];
int id[501];
int mn[501][501];
int n, m, i, j, k, l, s, len;
long long s1, s2;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    id[a[i]] = i;
  }
  for (i = 1; i <= m; i++) {
    mn[i][i] = a[i];
    for (j = i + 1; j <= m; j++)
      mn[i][j] = (mn[i][j - 1] < a[j] ? mn[i][j - 1] : a[j]);
  }
  f[1][0] = 1;
  for (i = 1; i <= m; i++) {
    f[i][i] = 1;
    f[i + 1][i] = 1;
  }
  for (len = 2; len <= m; len++) {
    for (i = 1; i <= m - len + 1; i++) {
      j = i + len - 1;
      s = id[mn[i][j]];
      s1 = 0;
      s2 = 0;
      for (k = i; k <= s; k++)
        s1 = (s1 + f[i][k - 1] * f[k][s - 1] % 998244353) % 998244353;
      for (l = s; l <= j; l++)
        s2 = (s2 + f[s + 1][l] * f[l + 1][j] % 998244353) % 998244353;
      f[i][j] = (f[i][j] + s1 * s2 % 998244353) % 998244353;
    }
  }
  printf("%I64d\n", f[1][m]);
}
