#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const int N = 500 + 10;
const int mod = 998244353;
inline void add(int& x, int y) { x = (x + y) % mod; }
int n, m, c[N];
int dp[N][N];
int main() {
  n = read(), m = read();
  for (register int i = 1; i <= m; ++i) c[i] = read();
  for (register int i = 0; i <= m; ++i) dp[i + 1][i] = 1;
  for (register int l = 1; l <= m; ++l)
    for (register int i = 1, j = i + l - 1; j <= m; ++i, ++j) {
      int mn = 1e9, p;
      for (register int k = i; k <= j; ++k)
        if (c[k] < mn) mn = c[k], p = k;
      int L = 0, R = 0;
      for (register int k = i; k <= p; ++k)
        add(L, 1ll * dp[i][k - 1] * dp[k][p - 1] % mod);
      for (register int k = p; k <= j; ++k)
        add(R, 1ll * dp[p + 1][k] * dp[k + 1][j] % mod);
      dp[i][j] = 1ll * L * R % mod;
    }
  printf("%d\n", dp[1][m]);
  return 0;
}
