Problem: This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of m and the time limit. You need to solve both subtasks in order to hack this one.

There are n+1 distinct colours in the universe, numbered 0 through n. There is a strip of paper m centimetres long initially painted with colour 0. 

Alice took a brush and painted the strip using the following process. For each i from 1 to n, in this order, she picks two integers 0 ≤ a_i < b_i ≤ m, such that the segment [a_i, b_i] is currently painted with a single colour, and repaints it with colour i. 

Alice chose the segments in such a way that each centimetre is now painted in some colour other than 0. Formally, the segment [i-1, i] is painted with colour c_i (c_i ≠ 0). Every colour other than 0 is visible on the strip.

Count the number of different pairs of sequences \\{a_i\}_{i=1}^n, \\{b_i\}_{i=1}^n that result in this configuration. 

Since this number may be large, output it modulo 998244353.

Input

The first line contains a two integers n, m (1 ≤ n ≤ 500, n = m) — the number of colours excluding the colour 0 and the length of the paper, respectively.

The second line contains m space separated integers c_1, c_2, …, c_m (1 ≤ c_i ≤ n) — the colour visible on the segment [i-1, i] after the process ends. It is guaranteed that for all j between 1 and n there is an index k such that c_k = j.

Note that since in this subtask n = m, this means that c is a permutation of integers 1 through n.

Output

Output a single integer — the number of ways Alice can perform the painting, modulo 998244353.

Examples

Input


3 3
1 2 3


Output


5


Input


7 7
4 5 1 6 2 3 7


Output


165

Note

In the first example, there are 5 ways, all depicted in the figure below. Here, 0 is white, 1 is red, 2 is green and 3 is blue.

<image>

Below is an example of a painting process that is not valid, as in the second step the segment 1 3 is not single colour, and thus may not be repainted with colour 2.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXCOLOR = 500;
const int MAXLEN = 1000000;
const int MAXLG = 19;
const int MOD = 998244353;
int ncolor, len;
int a[MAXLEN];
int mn[MAXLEN][MAXLG + 1];
int nxt[MAXLEN];
pair<int, int> o[MAXLEN];
int fst[MAXCOLOR + 1];
int getmn(int l, int r) {
  int len = r - l + 1, ret = INT_MAX, at = l;
  for (int k = MAXLG; k >= 0; --k)
    if (len & (1 << k)) ret = min(ret, mn[at][k]), at += 1 << k;
  return ret;
}
vector<int> calc(int l, int r, int lim) {
  int v = getmn(l, r);
  vector<int> pos;
  for (int x = fst[v]; x != -1; x = nxt[x]) {
    if (x < l || x > r) throw 1;
    pos.push_back(x);
  }
  assert(((int)(pos).size()) >= 1);
  vector<int> lres;
  if (pos[0] != l)
    lres = calc(l, pos[0] - 1, lim + 1);
  else
    lres = vector<int>(lim + 2, 1);
  assert(((int)(lres).size()) == lim + 2);
  vector<int> rres;
  if (pos.back() != r)
    rres = calc(pos.back() + 1, r, lim + 1);
  else
    rres = vector<int>(lim + 2, 1);
  assert(((int)(rres).size()) == lim + 2);
  int mlt = 1;
  for (int i = (1); i < (((int)(pos).size())); ++i)
    if (pos[i - 1] + 1 != pos[i]) {
      vector<int> mres = calc(pos[i - 1] + 1, pos[i] - 1, 0);
      assert(((int)(mres).size()) == 1);
      mlt = (long long)mlt * mres[0] % MOD;
    }
  vector<int> res(lim + 1, 0);
  for (int i = (1); i <= (lim + 1); ++i)
    for (int j = (1); j <= (lim - i + 2); ++j) {
      assert(j <= lim + 1 && i + j - 2 <= lim);
      res[i + j - 2] = (res[i + j - 2] + (long long)lres[i] * rres[j]) % MOD;
    }
  for (int i = (0); i < (((int)(res).size())); ++i)
    res[i] = (long long)res[i] * mlt % MOD;
  return res;
}
int solve() {
  for (int i = (0); i < (len); ++i) mn[i][0] = a[i];
  for (int k = (0); k < (MAXLG); ++k)
    for (int i = (0); i < (len); ++i) {
      mn[i][k + 1] = mn[i][k];
      if (i + (1 << k) < len)
        mn[i][k + 1] = min(mn[i][k + 1], mn[i + (1 << k)][k]);
    }
  for (int i = (0); i < (len); ++i) o[i] = make_pair(a[i], i);
  sort(o, o + len);
  for (int i = (0); i < (len); ++i)
    nxt[o[i].second] =
        i + 1 < len && o[i + 1].first == o[i].first ? o[i + 1].second : -1;
  for (int i = (1); i <= (ncolor); ++i) fst[i] = -1;
  for (int i = (0); i < (len); ++i)
    if (fst[a[i]] == -1) fst[a[i]] = i;
  try {
    vector<int> res = calc(0, len - 1, 0);
    return res[0];
  } catch (int e) {
    return 0;
  }
  return -1;
}
void run() {
  scanf("%d%d", &ncolor, &len);
  for (int i = (0); i < (len); ++i) scanf("%d", &a[i]);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}