import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[] nums = new int[m];
        for(int i = 0; i < m; i++){
            nums[i] = sc.nextInt();
        }
        TreeMap<Integer, Integer> blackBox = new TreeMap<>();
        blackBox.put(Integer.MAX_VALUE, 1);
        int size = 1;
        int curKey = Integer.MAX_VALUE;
        int curValue = 1;
        int curPosition = 0;
        for(int i = 0; i < n; i++){
            int req = sc.nextInt();
            for(int j = size - 1; j < req; j++){
                if (blackBox.containsKey(nums[j])) {
                    blackBox.put(nums[j], blackBox.get(nums[j]) + 1);
                    if (curKey == nums[j]) {
                        curValue++;
                    }
                }
                else {
                    blackBox.put(nums[j], 1);
                }
                if(nums[j] < curKey) {
                    if (curPosition == 0) {
                        Map.Entry<Integer, Integer> curEnrty= blackBox.lowerEntry(curKey);
                        curKey = curEnrty.getKey();
                        curValue = curEnrty.getValue();
                        curPosition = curValue - 1;
                    }
                    else {
                        curPosition--;
                    }
                }
            }
            size = req + 1;
            System.out.println(curKey);
            if (curPosition == curValue - 1) {
                 Map.Entry<Integer, Integer> curEnrty = blackBox.higherEntry(curKey);
                curKey = curEnrty.getKey();
                curValue = curEnrty.getValue();
                curPosition = 0;
            }
            else {
                curPosition++;
            }
        }
    }
}