#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int n, m;
int arr[N], u[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> m >> n;
for (int i = 1; i <= m; i++)
cin >> arr[i];
for (int i = 1; i <= n; i++) {
cin >> u[i];
}
priority_queue<int>a;
priority_queue<int, vector<int>, greater<int>>b;
int j = 0;
int k = 1;
for (int i = 1; i <= n; i++) {
j++;
while (k <= u[i]) {
for (; k <= u[i]; k++) {
if (b.empty() || arr[k] >= b.top())
b.push(arr[k]);
else
a.push(arr[k]);
while (a.size() > j)b.push(a.top()), a.pop();
while (a.size() < j)a.push(b.top()), b.pop();
}
}
while (a.size() > j)b.push(a.top()), a.pop();
while (a.size() < j)a.push(b.top()), b.pop();
cout << a.top() << '\n';
}
return 0;
}