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.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class E21108 {
	
	private static class Interval implements Comparable<Interval> {
		int l;
		int r;
		int h;
		
		Interval(int l,int r,int h) {
			this.l = l;
			this.r = r;
			this.h = h;
		}

		@Override
		public int compareTo(Interval inter) {
			if(this.l != inter.l) return this.l-inter.l; 
			return this.r-inter.r;
		}
	}
	
	private static class SegmentTree {
		SegmentTree left;
		SegmentTree right;
		SegmentTree p;
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;;
		int l;
		int r;
		int dmax;
		int dmin;
		
		SegmentTree(int l,int r,SegmentTree p) {
			if(l==r) {
				this.left = null;
				this.right = null;
				this.p = p;
				this.l = l;
				this.r = r;
			}
			else {
				int m = (l+r)/2;
				this.left = new SegmentTree(l,m,this);
				this.right = new SegmentTree(m+1,r,this);
				this.p = p;
				this.l = l;
				this.r = r;
			}
		}
		
		SegmentTree getSegment(int x) {
			if(this.l ==x && this.r == x) return this;
			int m = (l+r)/2;
			if(x<l || x>r) return null;
			if(x<=m) return left.getSegment(x);
			return right.getSegment(x);
		}
		
		void update(int max,int min) {
			this.dmin = this.min = min;
			this.dmax = this.max = max;
			if(p!=null) p.update();
		}
		
		private void update() {
			this.dmin = Math.min(left.dmin, right.dmin);
			this.dmax = Math.max(left.dmax, right.dmax);
			this.min = dmin;
			this.max = dmax;
			if(p!=null) p.update();
		}
		
		private void update(SegmentTree c,int x,int y) {
			SegmentTree o = (c==left)?right:left;
			int x1 = 0,y1=0;
			if(c.dmin<o.dmin && x==1){
				dmin--;
				x1 = x;
			}
			if(c.dmax>=o.dmax && y==1) {
				dmax--;
				y1=y;
			}
			updates.add(this);	
			if(p!=null) p.update(this,x1,y1);
		}
		
		void setRight() {
			this.dmax = this.max;
			this.dmin = this.min;
		}
		
		void decrement() {
			this.dmax--;
			this.dmin--;
			updates.add(this);
			if(p!=null) p.update(this,1,1);
		}
		
		int query(int l,int r,int action) {
			if(this.l == l && this.r == r) {
				switch(action) {
				case 0 :
					return min;
				case 1 :
					return max;
				case 3:
					decrement();
					return 0;
				}
			}
			int m = (this.l + this.r)/2;
			int v1=0,v2=0;
			if(action==0) v1=v2=Integer.MAX_VALUE;
			if(action==1) v1=v2=Integer.MIN_VALUE;
			if(l<=m) {
				v1 = left.query(l, Math.min(m, r), action); 
				if(r>m) v2 = right.query(m+1, r, action);
			}
			else return right.query(l, r, action);
			switch(action) {
			case 0:
				return Math.min(v1, v2);
			case 1:
				return Math.max(v1, v2);
			default:
				return 0;
			}
		}
		
	}
	
	private static int gMax = Integer.MIN_VALUE;
	
	private static List<Interval> gFin = null;
	
	private static Set<SegmentTree> updates = new HashSet<SegmentTree>();

	public static void main(String[] args) throws IOException {
//		BufferedReader br = new BufferedReader(new FileReader("F:/books/input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s1 = br.readLine().split(" ");
		int n = Integer.parseInt(s1[0]);
		int m = Integer.parseInt(s1[1]);
		SegmentTree root = new SegmentTree(0,n-1,null);
		String[] s2 = br.readLine().split(" ");
		for(int i=0;i<n;i++) {
			int v = Integer.parseInt(s2[i]);
			SegmentTree st = root.getSegment(i);
			st.update(v, v);
		}
		List<Interval> intrs = new ArrayList<Interval>();
		TreeSet<Integer> set = new TreeSet<Integer>();
		for(int i=0;i<m;i++) {
			String[] s3 = br.readLine().split(" ");
			int l = Integer.parseInt(s3[0])-1;
			int r = Integer.parseInt(s3[1])-1;
			int h = i+1;
			intrs.add(new Interval(l,r,h));
			set.add(l);
			set.add(r);
		}
		Collections.sort(intrs);
		set.add(0);
		gMax = root.max - root.min;
		gFin = new ArrayList<Interval>();
//		System.out.println("\n"+root.min + " " + root.max);
		int cur = -1;int prev = -1;
		for(int i : set) {
			prev = cur;
			cur = i;
			calc(cur,cur,intrs,root);
			if(prev==-1 || (cur-prev)<2) continue;
			calc(prev+1,cur-1,intrs,root);

//			System.out.println("\nminmax"+root.min + " " + root.max);
		}
		System.out.println(gMax);
		System.out.println(gFin.size());
		for(Interval i : gFin) System.out.print(i.h+" ");
//		System.out.println("\n"+root.min + " " + root.max);
	}

	private static List<Interval> getIntervals(int l, int r,
			List<Interval> intrs) {
		List<Interval> ret = new ArrayList<Interval>();
		for(Interval inter : intrs) {
			if(inter.l>r) break;
			if(inter.r>=l) ret.add(inter);
		}
		return ret;
	}

	private static void calc(int l, int r, List<Interval> intrs,
			SegmentTree root) {
		List<Interval> list = getIntervals(l,r,intrs);
		updates = new HashSet<SegmentTree>();
		for(Interval inter : list) {
			root.query(inter.l, inter.r, 3);
		}
		int ret = root.dmax - root.dmin;
//		System.out.println(ret + " " + l + " " + r + " " + root.dmax + " " + root.dmin);
//		for(Interval inter : list) {
//			root.query(inter.l, inter.r, 2);
//		}
		for(SegmentTree s : updates) s.setRight();
//		System.out.println(ret + " " + l + " " + r + " " + root.dmax + " " + root.dmin);
		if(ret>gMax) {
			gMax = ret;
			gFin = list;
		}
	}

}