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.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Artem Gilmudinov
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n, m;
            n = in.readInt();
            m = in.readInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            SegmentTreeMin stMin = new SegmentTreeMin(a);
            SegmentTreeMax stMax = new SegmentTreeMax(a);
            int l, r, x;
            PairInt f, s;
            for (int i = 0; i < m; i++) {
                l = in.readInt() - 1;
                r = in.readInt() - 1;
                x = in.readInt();
                f = stMin.get(0, stMin.size - 1, l, r, 0);
                s = stMax.get(0, stMax.size - 1, l, r, 0);
                if (f.y != x) {
                    out.println(f.x + 1);
                } else if (s.y != x) {
                    out.println(s.x + 1);
                } else {
                    out.println(-1);
                }
            }
        }

        class SegmentTreeMin {
            PairInt[] b;
            int size;
            PairInt fake = new PairInt(-1, Integer.MAX_VALUE);

            public SegmentTreeMin(int[] a) {
                size = 1;
                while (size < a.length) {
                    size *= 2;
                }
                b = new PairInt[2 * size - 1];
                for (int i = size - 1, j = 0; j < a.length; j++, i++) {
                    b[i] = new PairInt(j, a[j]);
                }
                for (int i = size - 1 + a.length; i < b.length; i++) {
                    b[i] = fake;
                }
                for (int i = size - 2; i >= 0; i--) {
                    if (b[2 * i + 1].y < b[2 * i + 2].y) {
                        b[i] = b[2 * i + 1].clone();
                    } else {
                        b[i] = b[2 * i + 2].clone();
                    }
                }
            }

            public PairInt get(int tl, int tr, int ql, int qr, int node) {
                if (ql > qr) {
                    return fake;
                }
                if (tl == ql && tr == qr) {
                    return b[node];
                }
                int mid = tl + (tr - tl) / 2;
                PairInt first = get(tl, mid, ql, Math.min(mid, qr), node * 2 + 1);
                PairInt second = get(mid + 1, tr, Math.max(mid + 1, ql), qr, node * 2 + 2);
                if (first.y < second.y) {
                    return first;
                } else {
                    return second;
                }
            }

        }

        class SegmentTreeMax {
            PairInt[] b;
            int size;
            PairInt fake = new PairInt(-1, Integer.MIN_VALUE);

            public SegmentTreeMax(int[] a) {
                size = 1;
                while (size < a.length) {
                    size *= 2;
                }
                b = new PairInt[2 * size - 1];
                for (int i = size - 1, j = 0; j < a.length; j++, i++) {
                    b[i] = new PairInt(j, a[j]);
                }
                for (int i = size - 1 + a.length; i < b.length; i++) {
                    b[i] = fake;
                }
                for (int i = size - 2; i >= 0; i--) {
                    if (b[2 * i + 1].y < b[2 * i + 2].y) {
                        b[i] = b[2 * i + 2].clone();
                    } else {
                        b[i] = b[2 * i + 1].clone();
                    }
                }
            }

            public PairInt get(int tl, int tr, int ql, int qr, int node) {
                if (ql > qr) {
                    return fake;
                }
                if (tl == ql && tr == qr) {
                    return b[node];
                }
                int mid = tl + (tr - tl) / 2;
                PairInt first = get(tl, mid, ql, Math.min(mid, qr), node * 2 + 1);
                PairInt second = get(mid + 1, tr, Math.max(mid + 1, ql), qr, node * 2 + 2);
                if (first.y < second.y) {
                    return second;
                } else {
                    return first;
                }
            }

        }

    }

    static class PairInt {
        public int x;
        public int y;

        public PairInt(int x, int y) {
            this.x = x;
            this.y = y;
        }


        public boolean equals(Object obj) {
            PairInt pairInt = (PairInt) obj;
            return pairInt.x == x && pairInt.y == y;
        }

        public String toString() {
            return x + " " + y;
        }

        public PairInt clone() {
            return new PairInt(x, y);
        }

    }

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

        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 readInt() {
            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;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}