#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b) { a = (a + b) % MOD; }
void mul(int64_t& a, int64_t b) { a = a * b % MOD; }
int main() {
  int N, M, A[500], pos[500];
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    pos[A[i]] = i;
  }
  static int64_t dp[501][501];
  dp[pos[N - 1]][pos[N - 1]] = 1;
  for (int i = N - 2; i >= 0; i--) {
    int p = pos[i];
    vector<int64_t> L(N), R(N);
    int lt = p, rt = p;
    while (lt > 0 && A[lt - 1] > i) lt--;
    while (rt < N - 1 && A[rt + 1] > i) rt++;
    L[p] = R[p] = 1;
    for (int j = p; j >= lt; j--) {
      for (int k = lt; k < j; k++) add(L[k], dp[k][j - 1] * L[j]);
    }
    for (int j = p; j <= rt; j++) {
      for (int k = rt; k > j; k--) add(R[k], dp[j + 1][k] * R[j]);
    }
    for (int l = lt; l <= p; l++)
      for (int r = p; r <= rt; r++) add(dp[l][r], L[l] * R[r]);
  }
  static int64_t DP[501];
  DP[0] = 1;
  for (int i = 0; i < N; i++)
    for (int j = i; j < N; j++) add(DP[j + 1], DP[i] * dp[i][j]);
  cout << DP[N] << endl;
  return 0;
}
