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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Stack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

    public static class SegmentTreeMin {
    public int height, maxsize, n;
    public long T[];
    public SegmentTreeMin(int[] a) {
        n = a.length;
        height = (int)Math.ceil((Math.log(a.length) / Math.log(2)));
        maxsize = (int)(2 * Math.pow(2, height) - 1);
        T = new long[maxsize + 1];
        init(1, a, 0, a.length - 1);
    }
    public void init(int x, int[] a, int l, int r) {
        if(l == r) {
            T[x] = a[l];
        }else {
            int m = (l + r) >> 1;
            init(x << 1, a, l, m);
            init((x << 1) | 1, a, m + 1, r);
            T[x] = Math.min(T[x << 1], T[(x << 1) | 1]);
        }
    }
    public long getMin(int x, int l, int r, int ll, int rr) {
        if(ll <= l && r <= rr) return T[x];
        if(r < ll || rr < l) return Long.MAX_VALUE;
        int m = (l + r) >> 1;
        return Math.min(getMin(x << 1, l, m, ll, rr), getMin((x << 1) | 1, m + 1, r, ll, rr));
    }
    public void update(int x, int l, int r, int i, int v) {
        if(l == r && l == i) {
            T[x] = v;
            return;
        }
        int m = (l + r) >> 1;
        if(l <= i && i <= m) update(x << 1, l, m, i, v);
        else if(m + 1 <= i && i <= r)update(x << 1 | 1, m + 1, r, i, v);
        T[x] = Math.min(T[x << 1], T[x << 1 | 1]);
    }
    public void update(int i, int v) {
        update(1, 0, n - 1, i, v);
    }
    public long getMin(int l, int r) {
        return getMin(1, 0, n - 1, l, r);
    }
}
public static class SegmentTreeMax {
    public int height, maxsize, n;
    public long T[];
    public SegmentTreeMax(int[] a) {
        n = a.length;
        height = (int)Math.ceil((Math.log(a.length) / Math.log(2)));
        maxsize = (int)(2 * Math.pow(2, height) - 1);
        T = new long[maxsize + 1];
        init(1, a, 0, a.length - 1);
    }
    public void init(int x, int[] a, int l, int r) {
        if(l == r) {
            T[x] = a[l];
        }else {
            int m = (l + r) >> 1;
            init(x << 1, a, l, m);
            init(x << 1 | 1, a, m + 1, r);
            T[x] = Math.max(T[x << 1], T[x << 1 | 1]);
        }
    }
    public long getMax(int x, int l, int r, int ll, int rr) {
        if(ll <= l && r <= rr) return T[x];
        if(r < ll || rr < l) return Long.MIN_VALUE;
        int m = (l + r) >> 1;
        return Math.max(getMax(x << 1, l, m, ll, rr), getMax(x << 1 | 1, m + 1, r, ll, rr));
    }
    public void update(int x, int l, int r, int i, int v) {
        if(l == r && l == i) {
            T[x] = v;
            return;
        }
        int m = (l + r) >> 1;
        if(l <= i && i <= m) update(x << 1, l, m, i, v);
        else if(m + 1 <= i && i <= r)update(x << 1 | 1, m + 1, r, i, v);
        T[x] = Math.max(T[x << 1], T[x << 1 | 1]);
    }
    public void update(int i, int v) {
        update(1, 0, n - 1, i, v);
    }
    public long getMax(int l, int r) {
        return getMax(1, 0, n - 1, l, r);
    }
}

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        InputReader in = new InputReader(inputStream);
        
        int n = in.nextInt(),m=in.nextInt();
        int[] a = in.nextArray(n);
        int[]next = new int[n+1];
        next[n-1]=-1;
        
        for(int i=n-2;i>=0;i--){
            if(a[i]!=a[i+1])next[i]=i+1;
            else next[i]=next[i+1];
        }
        for(int i = 0;i<n;i++){
            //System.out.print(next[i] + " ");
        }
        for(int i=0;i<m;i++){
            int l=in.nextInt()-1,r=in.nextInt()-1, x=in.nextInt();
            if(a[l]==x){
                int d=next[l];
                if(d==-1 || r<d) out.println(-1);
                else out.println(d+1);
            }else out.println(l+1);
        }
        out.close();
    }

    static class InputReader {

        BufferedReader reader;
        StringTokenizer tokenizer;

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        public double[] nextArrayd(int n) {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextDouble();
            }
            return a;
        }

        private BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public void printAr(int[] a) {
            System.out.print("[");
            for (long x : a) {
                System.out.print(x + ",");
            }
            System.out.print("]");
        }
    }

}