#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int n, m;
int v[502];
int mi[502][502];
long long dp[502][502];
long long s[502][502];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> v[i];
  for (int i = 1; i <= m; i++) {
    dp[i][i] = 1;
    s[i][i] = 2;
    dp[i][i - 1] = 1;
    dp[i + 1][i] = 1;
    s[i + 1][i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    mi[i][i] = i;
    for (int j = i + 1; j <= m; j++) {
      mi[i][j] = mi[i][j - 1];
      if (v[j] < v[mi[i][j]]) mi[i][j] = j;
    }
  }
  for (int i = m; i >= 1; i--)
    for (int j = i + 1; j <= m; j++) {
      int mip = mi[i][j];
      dp[i][j] = dp[i][mip - 1] * s[mip + 1][j] % MOD;
      for (int x = i; x < mip; x++)
        dp[i][j] = (dp[i][j] +
                    dp[i][x] * dp[x + 1][mip - 1] % MOD * s[mip + 1][j] % MOD) %
                   MOD;
      s[i][j] = dp[i][j];
      for (int x = i; x <= j; x++)
        s[i][j] = (s[i][j] + dp[i][x - 1] * dp[x][j]) % MOD;
    }
  cout << dp[1][m] << "\n";
  return 0;
}
