#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long M = 510;
long long arr[M];
long long memo[M][M];
long long solve(long long l, long long r) {
  if (l == r + 1) return 1;
  if (l > r) return 0;
  if (l == r) return 1;
  if (memo[l][r] != -1) return memo[l][r];
  long long minColor = M;
  long long minPos = -1;
  for (long long i = l; i <= r; ++i) {
    if (minColor > arr[i]) {
      minColor = arr[i];
      minPos = i;
    }
  }
  long long resLeft = 0;
  for (long long i1 = l; i1 <= minPos; ++i1) {
    long long temp = solve(l, i1 - 1) * solve(i1, minPos - 1) % mod;
    resLeft += temp;
    resLeft %= mod;
  }
  long long resRight = 0;
  for (long long i2 = minPos; i2 <= r; ++i2) {
    long long temp = solve(minPos + 1, i2) % mod * solve(i2 + 1, r) % mod;
    resRight += resLeft * temp % mod;
    resRight %= mod;
  }
  return memo[l][r] = resRight;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= m; ++i) {
    for (long long j = 1; j <= m; ++j) {
      memo[i][j] = -1;
    }
    cin >> arr[i];
  }
  cout << solve(1, m) << '\n';
}
