#include <bits/stdc++.h>

#define int long long
#define endl "\n"
#define mod 1000000007
#define inf 0xFFFFFFFFFFFFFFFL

using namespace std;

void solve()
{
	int n, q;
	cin >> n >> q;
	vector<int> v(n);
	int mn = INT_MAX, mx = INT_MIN;
	for (int i = 0; i < n; i++)
		cin >> v[i], mn = min(v[i], mn), mx = max(v[i], mx);

	vector<vector<int>> a;
	vector<int> temp;
	for (int i = 0; i < n; i++)
	{
		temp.push_back(v[i]);
		if (i == n - 1 or v[i] + 1 != v[i + 1])
		{
			a.push_back(temp);
			temp.clear();
		}
	}
	vector<int> till;
	int cnt = 0;
	for (auto x : a)
	{
		cnt++;
		if (cnt == 1)
		{
			till.push_back(x.front() - 1);
		}
		else
		{
			till.push_back((x.front() - temp.back()) + till.back() - 1);
		}
		temp = x;
		// cout << till.back() << endl;
	}
	while (q--)
	{
		int k;
		cin >> k;
		int in;
		int l = 0, r = till.size();

		while (r - l > 1)
		{
			int mid = (r + l) / 2;
			if (till[mid] >= k)
				r = mid;
			else if (till[mid] < k)
				l = mid;
		}
		in = l;
		// cout << in << endl;
		if (k <= till[0])
			cout << k << endl;
		else if (in == till.size() - 1)
			cout << k + n << endl;
		else
			cout << (a[in].back() + (k - till[in])) << endl;
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	srand(chrono::steady_clock::now().time_since_epoch().count());

	cout << fixed << setprecision(3) << endl;

	// int tt;
	// cin >> tt;
	// while (tt--)
	solve();

	cerr << endl
		 << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;

	return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=2e5+5;
vi adj[N],ex(N,0),ans(N,0),vis(N,0);
int mxd=0,root,timer=0,r1,r2;

void dfs(int u,int p,int d,int dd=0){
    if(d>mxd){
        root=u;
        mxd=d;
    }
    for(auto v: adj[u]){
        if(v!=p){
            if(dd){
                ex[v]=u;
            }
            dfs(v,u,d+1,dd);
        }
    }
}

void traverse(int u,int p){
    ans[u]=++timer;
    vis[u]=true;
    for(auto v: adj[u]){
        if(v==p || v==ex[u] || vis[v])
            continue;
        traverse(v,u);
    }   
    if(ex[u]!=0 && vis[ex[u]]==false) 
    traverse(ex[u],u);
    timer++;
}

void solve(){
    int n,u,v;
    cin>>n;
    fr(i,0,n-1){
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,0,1);
    r1=root;
    mxd=0;
    dfs(r1,0,1,1);
    r2=root;
    traverse(r2,0);
    fr(i,1,n+1){
        cout<<ans[i]<<" ";
    }
    return;
}

int main()
{
    boost();
    
    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}