#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAX_N = 501;
int dp[MAX_N][MAX_N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for (int i = 0; i < m; ++i) {
    cin >> c[i];
  }
  for (int i = 0; i <= n; ++i) {
    dp[i][i] = 1;
  }
  for (int len = 1; len <= n; ++len) {
    for (int l = 0; l + len <= n; ++l) {
      int mn = l;
      for (int i = l + 1; i < l + len; ++i) {
        if (c[mn] > c[i]) {
          mn = i;
        }
      }
      int sa = 0, sb = 0;
      for (int a = l; a <= mn; ++a) {
        sa += ((long long)dp[l][a] * dp[a][mn]) % MOD;
        if (sa >= MOD) {
          sa -= MOD;
        }
      }
      for (int b = mn + 1; b <= l + len; ++b) {
        sb += ((long long)dp[mn + 1][b] * dp[b][l + len]) % MOD;
        if (sb >= MOD) {
          sb -= MOD;
        }
      }
      dp[l][l + len] = ((long long)sa * sb) % MOD;
    }
  }
  cout << dp[0][c.size()] << '\n';
  return 0;
}
