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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.function.LongBinaryOperator;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        LightWriter out = new LightWriter(outputStream);
        F1ShortColorfulStrip solver = new F1ShortColorfulStrip();
        solver.solve(1, in, out);
        out.close();
    }

    static class F1ShortColorfulStrip {
        private static final int MOD = 998244353;
        private static int[] c;
        private static int[] p;
        private static int n;
        private static IntSegmentTree min;
        private static long[][] dp;

        public void solve(int testNumber, LightScanner in, LightWriter out) {
            // out.setBoolLabel(LightWriter.BoolLabel.YES_NO_FIRST_UP);
            n = in.ints();
            if (n != in.ints()) throw new RuntimeException();
            c = in.ints(n);
            min = new IntSegmentTree(
                    IntStream.of(c).mapToLong(i -> i - 1).toArray(),
                    Math::min,
                    Long.MAX_VALUE,
                    Math::min
            );
            p = new int[n];
            for (int i = 0; i < n; i++) {
                p[c[i] - 1] = i;
            }
            dp = new long[n][n];
            for (int i = 0; i < n; i++) Arrays.fill(dp[i], -1);
            out.ans(solve(0, n - 1)).ln();

            // validate
        /*
        IntSegmentTree st = new IntSegmentTree(IntStream.of(c).mapToLong(i -> i).toArray(), Math::min, Long.MAX_VALUE, Long::min);
        int[] left = new int[n + 1], right = new int[n + 1];
        Arrays.fill(left, - 1);
        Arrays.fill(right, -1);
        for (int i = 0; i < m; i++) {
            if (left[c[i]] == -1) left[c[i]] = i;
            right[c[i]] = i;
        }
        for (int i = 1; i <= n; i++) {
            if (st.query(left[i], right[i] + 1) < i) {
                out.ans(0).ln();
                return;
            }
        } */

        /*
        IntSegmentTree max = new IntSegmentTree(LongStream.range(0, m).map(i -> -1).toArray(), Math::max, -1, Math::max);
        IntSegmentTree min = new IntSegmentTree(LongStream.range(0, m).map(i -> m).toArray(), Math::max, m, Math::max);
        long ans = 1;
        for (int i = 0; i < n; i++) {
            long l = max.query(0, p[i]), r = min.query(p[i] + 1, m);
            System.out.println("i=" + i + " l=" + l + " r=" + r + " delta=" + (p[i] - l) * (r - p[i]));
            ans *= (p[i] - l) * (r - p[i]);
            ans %= MOD;
            max.update(p[i], i);
            min.update(p[i], i);
        }
        out.ans(ans).ln(); */
        }

        private static long solve(int l, int r) {
            if (r < 0 || n <= l || r <= l) return 1;
            if (dp[l][r] >= 0) return dp[l][r];
            int target = (int) min.query(l, r + 1);
            int index = p[target];
            //System.out.println("Calc: l="+l+" r="+r);
            long left = 0, right = 0;
            for (int cur = index; cur >= l && c[cur] >= target; cur--) {
                left += solve(l, cur - 1) * solve(cur, index - 1) % MOD;
                left %= MOD;
            }
            for (int cur = index; cur <= r && c[cur] >= target; cur++) {
                right += solve(index + 1, cur) * solve(cur + 1, r) % MOD;
                right %= MOD;
            }
            return dp[l][r] = (left * right) % MOD;
        }

    }

    static class IntSegmentTree {
        private final int n;
        private final int m;
        private final long[] tree;
        private final LongBinaryOperator op;
        private final LongBinaryOperator up;
        private final long zero;

        public IntSegmentTree(long[] array, LongBinaryOperator op, long zero, LongBinaryOperator up) {
            this.n = array.length;
            int msb = BitMath.extractMsb(n);
            this.m = n == msb ? msb : (msb << 1);
            this.tree = new long[m * 2 - 1];
            this.op = op;
            this.up = up;
            this.zero = zero;
            Arrays.fill(tree, zero);
            System.arraycopy(array, 0, this.tree, m - 1, array.length);
            for (int i = m - 2; i >= 0; i--) {
                tree[i] = op.applyAsLong(tree[2 * i + 1], tree[2 * i + 2]);
            }
        }

        public long query(int l, int r) {
            long left = zero, right = zero;
            l += m - 1;
            r += m - 1;
            while (l < r) {
                if ((l & 1) == 0) {
                    left = op.applyAsLong(left, tree[l]);
                }
                if ((r & 1) == 0) {
                    right = op.applyAsLong(tree[r - 1], right);
                }
                l = l / 2;
                r = (r - 1) / 2;
            }
            return op.applyAsLong(left, right);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(long l) {
            return ans(Long.toString(l));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static final class BitMath {
        private BitMath() {
        }

        public static int extractMsb(int v) {
            v = (v & 0xFFFF0000) > 0 ? v & 0xFFFF0000 : v;
            v = (v & 0xFF00FF00) > 0 ? v & 0xFF00FF00 : v;
            v = (v & 0xF0F0F0F0) > 0 ? v & 0xF0F0F0F0 : v;
            v = (v & 0xCCCCCCCC) > 0 ? v & 0xCCCCCCCC : v;
            v = (v & 0xAAAAAAAA) > 0 ? v & 0xAAAAAAAA : v;
            return v;
        }

    }
}