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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
 *
 * @author Student_303_03
 */
public class JavaApplication3 {

     public static void main(String[] args) {
        InputReader inputReader = new InputReader(System.in);
        int n = inputReader.nextInt();
        int m = inputReader.nextInt();

        List<Long> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(inputReader.nextLong());
        }

        List<Interval> q = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int left = inputReader.nextInt() - 1;
            int right = inputReader.nextInt() - 1;
            long x = inputReader.nextLong();
            q.add(new Interval(left, right, x));
        }

        List<Integer> ans = ans(a, q);

        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
        for (Integer i : ans) {
            if (i.equals(-1)) {
                writer.println(i);
            } else {
                writer.println(i + 1);
            }
        }

        writer.close();
    }

    public static List<Integer> ans(List<Long> a, List<Interval> query) {
        List<Integer> d = new ArrayList<>();
        for (int i = 0; i < a.size(); i++) {
            d.add(-1);
        }

        for (int i = 1; i < a.size(); i++) {
            if (a.get(i).equals(a.get(i - 1))) {
                d.set(i, d.get(i - 1));
            } else {
                d.set(i, i - 1);
            }
        }

        List<Integer> ans = new ArrayList<>();
        for (Interval interval : query) {
            if (a.get(interval.getRight()).equals(interval.getX())) {
                int possible = d.get(interval.getRight());
                if (possible >= interval.getLeft()) {
                    ans.add(d.get(interval.getRight()));
                } else {
                    ans.add(-1);
                }
            } else {
                ans.add(interval.getRight());
            }
        }

        return ans;
    }


    protected static class Interval {
        private final int left;
        private final int right;
        private final long x;

        public Interval(int left, int right, long x) {
            this.left = left;
            this.right = right;
            this.x = x;
        }

        public int getLeft() {
            return left;
        }

        public int getRight() {
            return right;
        }

        public long getX() {
            return x;
        }
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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