#include <iostream>
#include <vector>
#include <set>
#include <climits>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int m, n;
cin >> m >> n;
vector<int> nums(m);
for(int i = 0; i < m; i++){
cin >> nums[i];
}
multiset<int> blackBox;
blackBox.insert(INT_MAX);
auto it = blackBox.begin();
for(int i = 0; i < n; i++){
int req;
cin >> req;
for(int j = blackBox.size() - 1; j < req; j++){
blackBox.insert(nums[j]);
if(nums[j] < *it) it--;
}
cout << *it << endl;
it++;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8Y2xpbWl0cz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGludCBtLCBuOwogICAgY2luID4+IG0gPj4gbjsKICAgIHZlY3RvcjxpbnQ+IG51bXMobSk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKXsKICAgICAgICBjaW4gPj4gbnVtc1tpXTsKICAgIH0KICAgIG11bHRpc2V0PGludD4gYmxhY2tCb3g7CiAgICBibGFja0JveC5pbnNlcnQoSU5UX01BWCk7CiAgICBhdXRvIGl0ID0gYmxhY2tCb3guYmVnaW4oKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIGludCByZXE7CiAgICAgICAgY2luID4+IHJlcTsKICAgICAgICBmb3IoaW50IGogPSBibGFja0JveC5zaXplKCkgLSAxOyBqIDwgcmVxOyBqKyspewogICAgICAgICAgICBibGFja0JveC5pbnNlcnQobnVtc1tqXSk7CiAgICAgICAgICAgIGlmKG51bXNbal0gPCAqaXQpIGl0LS07CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgKml0IDw8IGVuZGw7CiAgICAgICAgaXQrKzsKICAgIH0KICAgIHJldHVybiAwOwp9