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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class CNotEqualOnASegment {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            ArrayList<Integer>[] pos = new ArrayList[(int) 1e6 + 5];
            for (int i = 0; i < pos.length; i++) pos[i] = new ArrayList<>();
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = in.nextIntArray(n);
            for (int i = 0; i < n; i++) {
                pos[a[i]].add(i);
            }
            for (int q = 0; q < m; q++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;
                int x = in.nextInt();
                int p1 = Collections.binarySearch(pos[x], l);
                int p2 = Collections.binarySearch(pos[x], r);
                if (p1 < 0) out.println(l + 1);
                else if (p2 < 0) out.println(r + 1);
                else {
                    if (p2 - p1 == r - l) {
                        out.println(-1);
                    } else {
                        int lo = p1;
                        int hi = p2;
                        while (hi - lo > 1) {
                            int mid = (lo + hi) / 2;
                            if (pos[x].get(mid) - pos[x].get(lo) > mid - lo) hi = mid;
                            else lo = mid;
                        }
                        out.println(pos[x].get(hi) - 1 + 1);
                    }
                }
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }
}