#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n, m, a[N], b[N], cnt = 1;
map<int,int> mp;
priority_queue<int,vector<int>,greater<int> > q;
priority_queue<int> que;
signed main (){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
cin >> b[i];
++mp[b[i]];
}
for (int i = 1; i <= n; ++i){
if (que.size() == 0) que.push(a[i]);
else if (que.top() >= a[i]) que.push(a[i]);
else q.push(a[i]);
while (que.size() > cnt) {
q.push(que.top());
que.pop();
}
if (mp.count(i)) {
while (mp[i] != 0){
cout << que.top() << '\n';
++cnt;
--mp[i];
if (q.size() == 0) continue;
que.push(q.top());
q.pop();
}
}
}
return 0;
}