#include <bits/stdc++.h>
using namespace std;
const int N = 507;
const long long mod = 998244353;
long long dp[N][N];
int c[N], st[N][20], pos[N];
int n, m;
void build() {
  for (int i = 1; i <= n; i++) {
    st[i][0] = c[i];
  }
  for (int j = 1; j <= 10; j++)
    for (int i = 1; i <= n; i++)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
int get(int l, int r) {
  int pow = int(log2((r - l + 1)));
  return min(st[l][pow], st[r - (1 << pow) + 1][pow]);
}
long long top_down(int l, int r) {
  if (l == r || l > r) return 1;
  if (dp[l][r]) return dp[l][r];
  int mn = pos[get(l, r)];
  long long left = 0, right = 0;
  for (int i = l; i <= mn; i++) {
    left += top_down(l, i - 1) * top_down(i, mn - 1);
    left %= mod;
  }
  for (int i = mn; i <= r; i++) {
    right += top_down(mn + 1, i) * top_down(i + 1, r);
    right %= mod;
  }
  dp[l][r] = (left % mod) * (right % mod);
  dp[l][r] %= mod;
  return dp[l][r];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    pos[c[i]] = i;
  }
  build();
  cout << top_down(1, n);
}
