Problem: You are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.

For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Each of the next m lines contains three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106) — the parameters of the i-th query.

Output

Print m lines. On the i-th line print integer pi — the position of any number not equal to xi in segment [li, ri] or the value  - 1 if there is no such number.

Examples

Input

6 4
1 2 1 1 3 5
1 4 1
2 6 2
3 4 1
3 4 2


Output

2
6
-1
4

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class NotEqualOnASegment {

	static class S {
		int p, id, l;

		public S(int p, int id, int l) {
			this.p = p;
			this.id = id;
			this.l = l;
		}

		@Override
		public String toString() {
			return "S [p=" + p + ", id=" + id + ", l=" + l + "]";
		}

	}

	public static int lower_bound(ArrayList<S> l, int key) {
		int lower = 0, upper = l.size() - 1, ans = -1;
		S last = l.get(upper);
		if (last.p + last.l - 1 < key)
			return -1;
		while (lower <= upper) {
			int mid = (lower + upper) / 2;
			if (key < l.get(mid).p)
				upper = mid - 1;
			else {
				lower = mid + 1;
				ans = mid;
			}
		}
		return ans;
	}

	static boolean b(int s, int e, int v) {
		return v >= s && v <= e;
	}

	public static void main(String[] args) throws IOException {
		File inputFile = new File("entrada");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] nm = readInts(line);
			int n = nm[0], m = nm[1];
			int[] a = readInts(in.readLine());
			ArrayList<S> l = new ArrayList<>(n);
			// if (n > 1 && a[0] != a[1])
			// l.add(new S(0, a[0], 1));
			int start = 0, val = a[0], size = 1;
			for (int i = 1; i < n; i++) {
				if (a[i] != a[i - 1]) {
					l.add(new S(start, val, size));
					val = a[i];
					start = i;
					size = 1;
				} else
					size++;
			}
			l.add(new S(start, val, size));
			for (int i = 0; i < m; i++) {
				int[] lrx = readInts(in.readLine());
				lrx[0]--;
				lrx[1]--;
				int index = lower_bound(l, lrx[0]), ans = -1;
				if (index >= 0) {
					S cur = l.get(index);
					while (cur.p <= lrx[1]) {
						if (cur.id != lrx[2]) {
							if (b(lrx[0], lrx[1], cur.p))
								ans = cur.p + 1;
							else if (b(lrx[0], lrx[1], cur.p + cur.l - 1))
								ans = cur.p + cur.l;
							else if (b(cur.p, cur.p + cur.l - 1, lrx[0]))
								ans = lrx[0]+1;
							if (ans != -1)
								break;
						}
						index++;
						if (index < l.size())
							cur = l.get(index);
						else
							break;
					}
				}
				out.append(ans + "\n");
			}
		}
		System.out.print(out);
	}

	public static int[] readInts(String line) {
		String[] w = line.trim().split("\\s+");
		int[] a = new int[w.length];
		for (int i = 0; i < a.length; i++)
			a[i] = Integer.parseInt(w[i]);
		return a;
	}

	public static long[] readLongs(String line) {
		String[] w = line.trim().split("\\s+");
		long[] a = new long[w.length];
		for (int i = 0; i < a.length; i++)
			a[i] = Long.parseLong(w[i]);
		return a;
	}

	public static double[] readDoubles(String line) {
		String[] w = line.trim().split("\\s+");
		double[] a = new double[w.length];
		for (int i = 0; i < a.length; i++)
			a[i] = Double.parseDouble(w[i]);
		return a;
	}
}