#include <bits/stdc++.h>
using namespace std;
const long long N = 555;
long long dp[N][N], minc[N][N];
long long c[N], p[N];
long long n, m;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = (1); i <= (m); i++) {
    cin >> c[i];
    p[c[i]] = i;
  }
  for (long long l = (1); l <= (m); l++) {
    for (long long r = (l); r <= (m); r++) {
      if (l <= r) {
        minc[l][r] = n + 1;
        for (long long x = (l); x <= (r); x++) {
          minc[l][r] = min(minc[l][r], c[x]);
        }
      }
    }
  }
  for (long long l = (0); l <= (m + 1); l++) {
    for (long long r = (0); r <= (m + 1); r++) {
      dp[l][r] = 1;
    }
  }
  for (long long s = (2); s <= (m); s++) {
    for (long long l = (1); l <= (m - s + 1); l++) {
      long long r = l + s - 1;
      long long pos = p[minc[l][r]];
      long long x = 0, y = 0;
      for (long long i = (l); i <= (pos); i++) {
        x += dp[l][i - 1] * dp[i][pos - 1] % 998244353;
        x %= 998244353;
      }
      for (long long i = (pos); i <= (r); i++) {
        y += dp[pos + 1][i] * dp[i + 1][r] % 998244353;
        y %= 998244353;
      }
      dp[l][r] = x * y % 998244353;
    }
  }
  long long ans = dp[1][m];
  cout << ans << "\n";
  return 0;
}
