// #include <bits/stdc++.h>
// using namespace std;
// #define int long long int
// int32_t main() {
// ios_base::sync_with_stdio(false);
// cin.tie(nullptr);
// int t;
// t = 1;
// // cin >> t;
// while (t--) {
// int n;
// cin >> n;
// int k;
// cin >> k;
// int A[n];
// for (int i = 0; i < n; i++) {
// cin >> A[i];
// }
// map<int,int> m;
// for(int i=0;i<n;i++){
// m[A[i]]=1;
// }
// int B[k];
// for (int i = 0; i < k; i++) {
// cin >> B[i];
// }
// sort(A, A + n);
// for(int i=0,j=0;i<n&&j<k;){
// if(A[i]>B[j]&&m[A[i]]==1){
// if(i==0){
// cout << -1 << endl;
// }
// else{
// cout << A[i-1] << endl;
// m[A[i-1]]=0;
// i=0;
// j++;
// }
// }
// else if(A[i]==B[j]&&m[A[i]]==1){
// cout << A[i] << endl;
// m[A[i]]=0;
// i=0;
// j++;
// }
// else{
// i++;
// }
// }
// }
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int k;
cin >> k;
int A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
map<int, int> m;
for (int i = 0; i < n; i++) {
m[A[i]] = 1;
}
int B[k];
for (int i = 0; i < k; i++) {
cin >> B[i];
}
sort(A, A + n);
for (int i = 0, j = 0; i < n && j < k;) {
if (A[i] > B[j] && m[A[i]] == 1) {
if (i == 0) {
cout << -1 << endl;
} else {
cout << A[i - 1] << endl;
m[A[i - 1]] = 0;
j++;
}
} else if (A[i] == B[j] && m[A[i]] == 1) {
cout << A[i] << endl;
m[A[i]] = 0;
j++;
} else {
i++;
}
}
return 0;
}
Ly8gI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyAjZGVmaW5lIGludCBsb25nIGxvbmcgaW50CgovLyBpbnQzMl90IG1haW4oKSB7Ci8vICAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKLy8gICAgIGNpbi50aWUobnVsbHB0cik7CgovLyAgICAgaW50IHQ7Ci8vICAgICB0ID0gMTsKLy8gICAgIC8vIGNpbiA+PiB0OwovLyAgICAgd2hpbGUgKHQtLSkgewovLyAgICAgICAgIGludCBuOwovLyAgICAgICAgIGNpbiA+PiBuOwovLyAgICAgICAgIGludCBrOwovLyAgICAgICAgIGNpbiA+PiBrOwovLyAgICAgICAgIGludCBBW25dOwovLyAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7Ci8vICAgICAgICAgICAgIGNpbiA+PiBBW2ldOwovLyAgICAgICAgIH0KLy8gICAgICAgICBtYXA8aW50LGludD4gbTsKLy8gICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKLy8gICAgICAgICAJbVtBW2ldXT0xOwovLyAgICAgICAgIH0KLy8gICAgICAgICBpbnQgQltrXTsKLy8gICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGs7IGkrKykgewovLyAgICAgICAgICAgICBjaW4gPj4gQltpXTsKLy8gICAgICAgICB9Ci8vICAgICAgICAgc29ydChBLCBBICsgbik7Ci8vICAgICAgICAgZm9yKGludCBpPTAsaj0wO2k8biYmajxrOyl7Ci8vICAgICAgICAgCWlmKEFbaV0+QltqXSYmbVtBW2ldXT09MSl7Ci8vICAgICAgICAgCQlpZihpPT0wKXsKLy8gICAgICAgICAJCQljb3V0IDw8IC0xIDw8IGVuZGw7Ci8vICAgICAgICAgCQl9Ci8vICAgICAgICAgCQllbHNlewovLyAgICAgICAgIAkJY291dCA8PCBBW2ktMV0gPDwgZW5kbDsKLy8gICAgICAgICAJCW1bQVtpLTFdXT0wOwovLyAgICAgICAgIAkJaT0wOwovLyAgICAgICAgIAkJaisrOwkKLy8gICAgICAgICAJCX0KICAgICAgICAJCQovLyAgICAgICAgIAl9Ci8vICAgICAgICAgCWVsc2UgaWYoQVtpXT09QltqXSYmbVtBW2ldXT09MSl7Ci8vICAgICAgICAgCQljb3V0IDw8IEFbaV0gPDwgZW5kbDsKLy8gICAgICAgICAJCW1bQVtpXV09MDsKLy8gICAgICAgICAJCWk9MDsKLy8gICAgICAgICAJCWorKzsKLy8gICAgICAgICAJfQovLyAgICAgICAgIAllbHNlewovLyAgICAgICAgIAkJaSsrOwovLyAgICAgICAgIAl9Ci8vICAgICAgICAgfQovLyAgICAgfQovLyAgICAgcmV0dXJuIDA7Ci8vIH0KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBsb25nIGxvbmcgaW50CgppbnQzMl90IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CgogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIGludCBrOwogICAgY2luID4+IGs7CgogICAgaW50IEFbbl07CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGNpbiA+PiBBW2ldOwogICAgfQoKICAgIG1hcDxpbnQsIGludD4gbTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgbVtBW2ldXSA9IDE7CiAgICB9CgogICAgaW50IEJba107CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGs7IGkrKykgewogICAgICAgIGNpbiA+PiBCW2ldOwogICAgfQoKICAgIHNvcnQoQSwgQSArIG4pOwoKICAgIGZvciAoaW50IGkgPSAwLCBqID0gMDsgaSA8IG4gJiYgaiA8IGs7KSB7CiAgICAgICAgaWYgKEFbaV0gPiBCW2pdICYmIG1bQVtpXV0gPT0gMSkgewogICAgICAgICAgICBpZiAoaSA9PSAwKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IC0xIDw8IGVuZGw7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IEFbaSAtIDFdIDw8IGVuZGw7CiAgICAgICAgICAgICAgICBtW0FbaSAtIDFdXSA9IDA7CiAgICAgICAgICAgICAgICBqKys7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKEFbaV0gPT0gQltqXSAmJiBtW0FbaV1dID09IDEpIHsKICAgICAgICAgICAgY291dCA8PCBBW2ldIDw8IGVuZGw7CiAgICAgICAgICAgIG1bQVtpXV0gPSAwOwogICAgICAgICAgICBqKys7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaSsrOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gMDsKfQo=