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.util.*;
import java.io.*;
import static java.lang.Math.*;
public class MainS {
    static final long MOD = 1_000_000_007, INF = 1_000_000_000_000_000_000L;
    static final int INf = 1_000_000_000;
    static FastReader reader;
    static PrintWriter writer;

    public static void main(String[] args) {
        Thread t = new Thread(null, new O(), "Integer.MAX_VALUE", 100000000);
        t.start();
    }

    static class O implements Runnable {
        public void run() {
            try {
                magic();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }

    static void magic() throws IOException {
        reader = new FastReader();
        writer = new PrintWriter(System.out, true);
        int n = reader.nextInt(), m = reader.nextInt();
        ArrayList<Integer> occ[] = new ArrayList[1000001];
        for(int i=1;i<=n;++i) {
            int x = reader.nextInt();
            if(occ[x]==null) {
                occ[x] = new ArrayList<>();
            }
            occ[x].add(i);
        }
        StringBuilder fast = new StringBuilder();
        for(int i=0;i<m;++i) {
            int l = reader.nextInt(), r = reader.nextInt(), x = reader.nextInt();
            int L = countLessEqual(occ[x], l-1);
            int R = countLessEqual(occ[x], r);
            if(R-L == r-l+1) {
                fast.append(-1);
            }
            else {
                int low = l, high = r, mid, ans = r;
                while(low<=high) {
                    mid = (low+high)>>1;
                    if(countLessEqual(occ[x], mid) - L < mid-l+1) {
                        ans = mid;
                        high = --mid;
                    }
                    else {
                        low = ++mid;
                    }
                }
                fast.append(ans);
            }
            fast.append("\n");
        }
        writer.println(fast);
    }
    static int countLessEqual(ArrayList<Integer> list, int k) {
        if(list==null || list.isEmpty() || list.get(0)>k) {
            return 0;
        }
        int low = 0, high = list.size()-1, mid, ans = 0;
        while(low<=high) {
            mid = (low+high)>>1;
            if(list.get(mid)<=k) {
                ans = mid;
                low = ++mid;
            }
            else {
                high = --mid;
            }
        }
        return (ans+1);
    }
}