#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto i : v) os << i << " ";
  return os;
}
const long long MOD = 998244353;
const long long N = 1050;
long long a[N], f[N][N], idx[N][N];
long long dfs(long long l, long long r) {
  if (f[l][r] != -1) return f[l][r];
  long long ret = 0;
  long long pos = idx[l][r];
  long long p1 = 0, p2 = 0, p;
  for (long long L = l; L <= pos; ++L) {
    p = 1;
    if (L > l) p = 1ll * p * dfs(l, L - 1) % MOD;
    if (L < pos) p = 1ll * p * dfs(L, pos - 1) % MOD;
    p1 = (1ll * p1 + p) % MOD;
  }
  for (long long R = pos; R <= r; ++R) {
    p = 1;
    if (R > pos) p = 1ll * p * dfs(pos + 1, R) % MOD;
    if (R < r) p = 1ll * p * dfs(R + 1, r) % MOD;
    p2 = (1ll * p2 + p) % MOD;
  }
  return f[l][r] = (1ll * p1 * p2) % MOD;
}
int main() {
  memset(f, -1, sizeof(f));
  long long n, m;
  scanf("%I64d%I64d", &n, &m);
  for (long long i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  for (long long i = 0; i < n; ++i) idx[i][i] = i;
  for (long long l = 1; l < n; ++l)
    for (long long i = 0; i + l - 1 < n; ++i) {
      long long j = i + l - 1;
      if (i > 1) idx[i - 1][j] = (a[i - 1] < a[idx[i][j]]) ? i - 1 : idx[i][j];
      if (j < n) idx[i][j + 1] = (a[j + 1] < a[idx[i][j]]) ? j + 1 : idx[i][j];
    }
  printf("%I64d\n", dfs(0, n - 1));
  return 0;
}
