#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 998244353;
const int INF = 2e9;
int A[505], pos[505];
long long dp[505][505];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &A[i]);
    pos[A[i]] = i;
  }
  for (int i = 1; i <= m + 1; i++) dp[i][i - 1] = 1;
  for (int k = 1; k <= m; k++) {
    for (int i = 1; i <= m; i++) {
      int j = i + k - 1;
      if (j > m) break;
      int mi = 1;
      while (pos[mi] < i || pos[mi] > j) mi++;
      long long sum1 = 0, sum2 = 0;
      for (int _ = pos[mi]; _ >= i; _--) {
        sum1 = (sum1 + dp[i][_ - 1] * dp[_][pos[mi] - 1]) % mod;
      }
      for (int _ = pos[mi]; _ <= j; _++) {
        sum2 = (sum2 + dp[pos[mi] + 1][_] * dp[_ + 1][j]) % mod;
      }
      dp[i][j] = sum1 * sum2 % mod;
    }
  }
  printf("%lld\n", dp[1][m]);
  return 0;
}
