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 JAVA):

Solution:
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/*
procrastinating
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10);
    static final int MOD = (int) (998244353);

    static int n;
    static int[] c, pos;
    static SparseTable st;
    static long[][] dpAns, dpSum;

    static long mul(long a, long b) {
        return (a * b) % MOD;
    }

    static class SparseTable {
        int n, logn;
        int[] log;
        int[][] table;

        void build(int[] arr) {
            n = arr.length;
            log = new int[n + 1];
            log[1] = 0;
            for (int i = 2; i <= n; i++)
                log[i] = log[i / 2] + 1;
            logn = log[n] + 1;

            table = new int[n][logn];
            for (int i = 0; i < n; i++)
                table[i][0] = arr[i];
            for (int j = 1; j < logn; j++)
                for (int i = 0; i + (1 << j) <= n; i++)
                    table[i][j] = Math.min(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]);
        }

        int minOn(int l, int r) {
            int j = log[r - l + 1];
            return Math.min(table[l][j], table[r - (1 << j) + 1][j]);
        }
    }

    static void solve() {
        n = in.nextInt();
        in.nextInt();

        c = new int[n];
        pos = new int[n + 1];
        for (int i = 0; i < n; i++) {
            c[i] = in.nextInt();
            pos[c[i]] = i;
        }

        st = new SparseTable();
        st.build(c);

        dpAns = new long[n][n];
        dpSum = new long[n][n];
        for (int i = 0; i < n; i++) {
            dpAns[i][i] = 1;
            dpSum[i][i] = 2;
        }
        for (int j = 2; j <= n; j++) {
            for (int i = 0; i + j <= n; i++) {
                int l = i;
                int r = i + j - 1;
                int min = st.minOn(l, r);
                int m = pos[min];

                long val = 1;
                if (l < m)
                    val = mul(val, dpSum[l][m - 1]);
                if (m < r)
                    val = mul(val, dpSum[m + 1][r]);
                dpAns[l][r] = val;

                long sum = mul(val, 2);
                for (int k = l; k < r; k++)
                    sum = (sum + mul(dpAns[l][k], dpAns[k + 1][r])) % MOD;
                dpSum[l][r] = sum;
            }
        }

        out.println(dpAns[0][n - 1]);

    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));


        Thread thread = new Thread(null, () -> {
            int tests = 1;
//            tests = in.nextInt();

            while (tests-- > 0) {
                solve();
            }
        }, "Go", 1 << 29);
        thread.start();
        thread.join();


//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}