Problem: The only difference between easy and hard versions is a number of elements in the array.

You are given an array a consisting of n integers. The value of the i-th element of the array is a_i.

You are also given a set of m segments. The j-th segment is [l_j; r_j], where 1 ≤ l_j ≤ r_j ≤ n.

You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array a = [0, 0, 0, 0, 0] and the given segments are [1; 3] and [2; 4] then you can choose both of them and the array will become b = [-1, -2, -2, -1, 0].

You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array a and obtain the array b then the value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i will be maximum possible.

Note that you can choose the empty set.

If there are multiple answers, you can print any.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

Input

The first line of the input contains two integers n and m (1 ≤ n ≤ 300, 0 ≤ m ≤ 300) — the length of the array a and the number of segments, respectively.

The second line of the input contains n integers a_1, a_2, ..., a_n (-10^6 ≤ a_i ≤ 10^6), where a_i is the value of the i-th element of the array a.

The next m lines are contain two integers each. The j-th of them contains two integers l_j and r_j (1 ≤ l_j ≤ r_j ≤ n), where l_j and r_j are the ends of the j-th segment.

Output

In the first line of the output print one integer d — the maximum possible value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i if b is the array obtained by applying some subset of the given segments to the array a.

In the second line of the output print one integer q (0 ≤ q ≤ m) — the number of segments you apply.

In the third line print q distinct integers c_1, c_2, ..., c_q in any order (1 ≤ c_k ≤ m) — indices of segments you apply to the array a in such a way that the value max_{i=1}^{n}b_i - min_{i=1}^{n}b_i of the obtained array b is maximum possible.

If there are multiple answers, you can print any.

Examples

Input


5 4
2 -2 3 1 2
1 3
4 5
2 5
1 3


Output


6
2
1 4 


Input


5 4
2 -2 3 1 4
3 5
3 4
2 4
2 5


Output


7
2
3 2 


Input


1 0
1000000


Output


0
0

Note

In the first example the obtained array b will be [0, -4, 1, 1, 2] so the answer is 6.

In the second example the obtained array b will be [2, -3, 1, -1, 4] so the answer is 7.

In the third example you cannot do anything so the answer is 0.

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class E1ArrayAndSegmentsEasyVersion {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int m = in.scanInt();
            long arr[] = new long[n + 1];
            int ranges[][] = new int[m + 1][];
            for (int i = 1; i <= n; i++) arr[i] = in.scanInt();
            for (int i = 1; i <= m; i++) ranges[i] = new int[]{in.scanInt(), in.scanInt()};
            SegLazyMAX smax = new SegLazyMAX(n + 5);
            SegLazyMIN smin = new SegLazyMIN(n + 5);
            for (int i = 1; i <= n; i++) {
                smax.update(i, i, arr[i]);
                smin.update(i, i, arr[i]);
            }
//        for (int i = 1; i <= n; i++) {
//            out.println(smax.queryRange(1, 0, n + 4, i, i));
//            out.println(smin.queryRange(1, 0, n + 4, i, i));
//        }
            long ans = Integer.MIN_VALUE;
            int index = -1;
            for (int i = 1; i <= n; i++) {
                long pre[] = new long[n + 5];
                for (int j = 1; j <= m; j++) {
                    if (ranges[j][0] <= i && i <= ranges[j][1]) {
                    } else {
                        smax.update(ranges[j][0], ranges[j][1], -1);
                        smin.update(ranges[j][0], ranges[j][1], -1);
                    }
                }


                long min = smin.queryRange(1, 0, n + 4, 1, n);
                long max = smax.queryRange(1, 0, n + 4, 1, n);


                for (int j = 1; j <= m; j++) {
                    if (ranges[j][0] <= i && i <= ranges[j][1]) {
                    } else {
                        smax.update(ranges[j][0], ranges[j][1], +1);
                        smin.update(ranges[j][0], ranges[j][1], +1);
                    }
                }

                if (max - min >= ans) {
                    ans = max - min;
                    index = i;
                }
            }
            out.println(ans);
            ArrayList<Integer> appled = new ArrayList<>();

            for (int j = 1; j <= m; j++) {
                if (ranges[j][0] <= index && index <= ranges[j][1]) {
                } else {
                    appled.add(j);
                }
            }


            out.println(appled.size());
            for (int kk : appled) out.print(kk + " ");


        }

        public class SegLazyMAX {
            int n;
            long[] tree;
            long[] lazy;

            public SegLazyMAX(int n) {
                this.n = n;
                this.tree = new long[(4 * n) + 5];
                this.lazy = new long[(4 * n) + 5];
            }

            public void update(int l, int r, long val) {
                update(1, 0, n - 1, l, r, val);
            }

            private void update(int node, int start, int end, int l, int r, long val) {
                LAZY(node, start, end);
                if (start > end || start > r || end < l) return;
                if (start >= l && end <= r) {
                    tree[node] += val;
                    if (start != end) {
                        lazy[node * 2] += val;
                        lazy[(node * 2) + 1] += val;
                    }
                    return;
                }
                int mid = (start + end) / 2;
                update(node * 2, start, mid, l, r, val);
                update((node * 2) + 1, mid + 1, end, l, r, val);
                tree[node] = Math.max(tree[node * 2], tree[(node * 2) + 1]);
            }

            private void LAZY(int node, int start, int end) {
                if (lazy[node] != 0) {
                    tree[node] += lazy[node];
                    if (start != end) {
                        lazy[node * 2] += lazy[node];
                        lazy[(node * 2) + 1] += lazy[node];
                    }
                    lazy[node] = 0;
                }
            }

            private long queryRange(int node, int start, int end, int l, int r) {
                if (start > end || start > r || end < l) return Long.MIN_VALUE;
                LAZY(node, start, end);
                if (start >= l && end <= r) return (tree[node]);
                int mid = (start + end) / 2;
                long p1 = queryRange(node * 2, start, mid, l, r);
                long p2 = queryRange((node * 2) + 1, mid + 1, end, l, r);
                return Math.max(p1, p2);
            }

        }

        public class SegLazyMIN {
            int n;
            long[] tree;
            long[] lazy;

            public SegLazyMIN(int n) {
                this.n = n;
                this.tree = new long[(4 * n) + 5];
                this.lazy = new long[(4 * n) + 5];
            }

            public void update(int l, int r, long val) {
                update(1, 0, n - 1, l, r, val);
            }

            private void update(int node, int start, int end, int l, int r, long val) {
                LAZY(node, start, end);
                if (start > end || start > r || end < l) return;
                if (start >= l && end <= r) {
                    tree[node] += val;
                    if (start != end) {
                        lazy[node * 2] += val;
                        lazy[(node * 2) + 1] += val;
                    }
                    return;
                }
                int mid = (start + end) / 2;
                update(node * 2, start, mid, l, r, val);
                update((node * 2) + 1, mid + 1, end, l, r, val);
                tree[node] = Math.min(tree[node * 2], tree[(node * 2) + 1]);
            }

            private void LAZY(int node, int start, int end) {
                if (lazy[node] != 0) {
                    tree[node] += lazy[node];
                    if (start != end) {
                        lazy[node * 2] += lazy[node];
                        lazy[(node * 2) + 1] += lazy[node];
                    }
                    lazy[node] = 0;
                }
            }

            private long queryRange(int node, int start, int end, int l, int r) {
                if (start > end || start > r || end < l) return Long.MAX_VALUE;
                LAZY(node, start, end);
                if (start >= l && end <= r) return (tree[node]);
                int mid = (start + end) / 2;
                long p1 = queryRange(node * 2, start, mid, l, r);
                long p2 = queryRange((node * 2) + 1, mid + 1, end, l, r);
                return Math.min(p1, p2);
            }

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}