#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int MAX = 1010;
int c[MAX];
int p[MAX];
ll res[MAX][MAX];
const int MOD = 998244353;
void nope() {
  printf("0\n");
  exit(0);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &c[i]);
    p[c[i]] = i;
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i + j <= m; i++) {
      if (j == 0) {
        res[i][j] = 1;
        continue;
      }
      int mini = m;
      for (int k = i; k <= i + j; k++) {
        mini = min(mini, c[k]);
      }
      if (p[mini] == i) {
        for (int pos = i + 1; pos < i + j; pos++) {
          res[i][j] = (res[i][j] + res[i + 1][pos - i - 1] *
                                       res[pos + 1][i + j - pos - 1]) %
                      MOD;
        }
        res[i][j] = (res[i][j] + 2 * res[i + 1][j - 1]) % MOD;
        continue;
      }
      if (p[mini] == i + j) {
        for (int pos = i + j - 1; pos > i; pos--) {
          res[i][j] =
              (res[i][j] + res[i][pos - 1 - i] * res[pos][i + j - 1 - pos]) %
              MOD;
        }
        res[i][j] = (res[i][j] + 2 * res[i][j - 1]) % MOD;
        continue;
      }
      res[i][j] = (res[i][p[mini] - i] * res[p[mini]][i + j - p[mini]]) % MOD;
    }
  }
  printf("%lld\n", res[1][m - 1]);
}
