Link to this code: https://cses.fi/paste/8ae8898f755b7c73269cfc/
/*
  author: @ankingcodes
  created: 2021-07-17 20:17:57.530101
*/
        
#include<bits/stdc++.h>
#include<algorithm>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define MOD 1000000007

typedef tree<int, null_type, less<int>, rb_tree_tag,
                tree_order_statistics_node_update> PBDS;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
                tree_order_statistics_node_update> pairPBDS;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m; cin >> n >> m;
  ll t;
  multiset<int> a;
  for (int i=0;i<n;i++) {
    cin>>t;
    a.insert(t);
  }
  for (int i=0;i<m;i++) {
    cin >> t;
    auto it = a.upper_bound(t);
    if (it == a.begin()) cout << -1 << endl;
    else {
      cout << *(--it) << endl;
      a.erase(it);
    }
  }
  return 0;
}