#include <cstdio>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define LOG(x) cerr << #x << " = " << (x) << "\n"

typedef long long llint;
typedef pair<int,int> pii;

const int MAX = 100010, TOUR = 1<<17;

struct tour {
  int val, broj, prop;
  tour (int val, int broj, int prop) : val(val), broj(broj), prop(prop) {}
  tour () {}
} t[2*TOUR];

struct event {
  int t, l, r, val;
  event (int t, int l, int r, int val) : t(t), l(l), r(r), val(val) {}
  event () {}
};

bool operator < (const event &a, const event &b)
{
  return a.t < b.t;
}

vector <int> V[MAX];
vector <event> E;
int disc[MAX], fin[MAX];
int rje[MAX];
int vr=0;

void Propagiraj(int x)
{
  for (int i=2*x; i<=2*x+1; i++) {
    t[i].prop += t[x].prop;
    t[i].val += t[x].prop;
  }

  t[x].prop = 0;
}

tour Merge(tour l, tour r)
{
  if (l.val < r.val)
    return tour(l.val, l.broj, 0);
  if (r.val < l.val)
    return tour(r.val, r.broj, 0);
  return tour(l.val, l.broj + r.broj, 0);
}

void Stavi(int pos, int lo, int hi, int begin, int end, int val)
{
  if (lo >= end || hi <= begin)
    return;
  if (lo >= begin && hi <= end) {
    t[pos].val += val;
    t[pos].prop += val;
    return;
  }

  Propagiraj(pos);
  Stavi(2*pos+0, lo, (lo+hi)/2, begin, end, val);
  Stavi(2*pos+1, (lo+hi)/2, hi, begin, end, val);

  t[pos] = Merge(t[2*pos], t[2*pos+1]);
}

void Dfs(int node, int prosli)
{
  disc[node] = vr++;

  for (int i=0; i<(int) V[node].size(); i++) {
    int nn = V[node][i];
    if (nn != prosli)
      Dfs(nn, node);
  }

  fin[node] = vr;
}

void Init(int n)
{
  for (int i=0; i<n; i++)
    t[i+TOUR] = tour(0, 1, 0);

  for (int i=n; i<TOUR; i++)
    t[i+TOUR] = tour(1e9, 0, 0);

  for (int i=TOUR-1; i; i--)
    t[i] = Merge(t[2*i], t[2*i+1]);
}

int main()
{
  int n, brq;

  scanf("%d%d", &n, &brq);

  Init(n);

  for (int i=0; i<n-1; i++) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  Dfs(0, -1);

  for (int i=0; i<brq; i++) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    E.push_back(event(disc[a], disc[a], fin[a], 1));
    E.push_back(event(fin[a], disc[a], fin[a], -1));
    E.push_back(event(disc[b], disc[a], fin[a],  1));
    E.push_back(event(fin[b], disc[a], fin[a], -1));

    E.push_back(event(disc[a], disc[b], fin[b], 1));
    E.push_back(event(fin[a], disc[b], fin[b], -1));
    E.push_back(event(disc[b], disc[b], fin[b],  1));
    E.push_back(event(fin[b], disc[b], fin[b], -1));
  }

  sort(E.begin(), E.end());

  for (int i=0, ind=0; i<n; i++) {
    for (; ind < (int) E.size() && E[ind].t == i; ind++) {
      event ev = E[ind];
      Stavi(1, 0, TOUR, ev.l, ev.r, ev.val);
    }

    if (t[1].val)
      rje[i] = 0;
    else
      rje[i] = max(0, n - t[1].broj - 1);
  }

  for (int i=0; i<n; i++)
    printf("%d ", rje[disc[i]]);
  printf("\n");

  return 0;
}


#include <bits/stdc++.h>
#define MAX 100010
using namespace std;
typedef struct w
{
	int ini, fim, m, quanm, lazy;
} node;
int n,m,cur = 1,n1,n2;
int resp[MAX],marc[MAX],line[2*MAX],v[2*MAX];
node SEG[8*MAX];
bool check[MAX];
vector<int> grafo[MAX], lista[MAX];
map<int,int> en, ex;
void refresh(int id)
{
	if(SEG[id].lazy == 0) return;
	int lz = SEG[id].lazy; SEG[id].lazy = 0;
	SEG[id].m += lz;
	if(SEG[id].ini == SEG[id].fim) return;
	SEG[2*id].lazy += lz;
	SEG[2*id + 1].lazy += lz;
}
node merge(node a, node b)
{
	node p;
	p.ini = min(a.ini,b.ini); p.fim = max(a.fim,b.fim);
	if(a.m == b.m) p.quanm = a.quanm + b.quanm;
	else if(a.m > b.m) p.quanm = b.quanm;
	else p.quanm = a.quanm;
	p.m = min(a.m,b.m);
	p.lazy = 0;
	return p;
}
void build(int id, int i, int j)
{
	SEG[id].ini = i; SEG[id].fim = j;
	SEG[id].lazy = 0;
	if(i == j)
	{
		SEG[id].m = 0;
		SEG[id].quanm = 1;
		return;
	}
	int m = (i + j)/2;
	build(2*id,i,m); build(2*id + 1,m + 1,j);
	SEG[id] = merge(SEG[2*id],SEG[2*id + 1]);
	//SEG[id].lazy = 0;
}
void update(int id, int i, int j, int val)
{
	refresh(id);
	if(SEG[id].ini > j || SEG[id].fim < i) return;
	if(SEG[id].ini >= i && SEG[id].fim <= j)
	{
		SEG[id].lazy += val;
		refresh(id);
		return;
	}
	update(2*id,i,j,val); update(2*id + 1,i,j,val);
	SEG[id] = merge(SEG[2*id],SEG[2*id + 1]);
}
bool query(int id, int cur)
{
	refresh(id);
	if(SEG[id].ini > cur || SEG[id].fim < cur) return false;
	if(SEG[id].ini == SEG[id].fim)
	{
		if(SEG[id].m == 0) return true;
		else return false;
	}
	return query(2*id,cur) || query(2*id + 1,cur);
}
void DFS_linearizacao(int i)
{
	marc[i] = 1;
	en[i] = cur;
	line[cur++] = i;
	int tam = grafo[i].size();
	for(int g = 0 ; g < tam ; g++)
	{
		int prox = grafo[i][g];
		if(marc[prox] == 1) continue;
		DFS_linearizacao(prox);
	}
	ex[i] = cur;
	line[cur++] = i;
}
void DFS_processamento(int i)
{
	marc[i] = 2;
	int tam = lista[i].size();
	if(check[i]) for(int g = 0 ; g < tam ; g++) update(1,en[lista[i][g]],ex[lista[i][g]],1);
	if(SEG[1].m == 0) resp[i] = (2*n - SEG[1].quanm)/2;
	else resp[i] = n;
	if(resp[i] > 0) resp[i]--;
	tam = grafo[i].size();
	for(int g = 0 ; g < tam ; g++)
	{
		int prox = grafo[i][g];
		if(marc[prox] == 2) continue;
		DFS_processamento(prox);
	}
	tam = lista[i].size();
	if(check[i]) for(int g = 0 ; g < tam ; g++) update(1,en[lista[i][g]],ex[lista[i][g]],-1);
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int g = 0 ; g < n - 1 ; g++)
	{
		scanf("%d %d",&n1,&n2);
		grafo[n1].push_back(n2); grafo[n2].push_back(n1);
	}
	for(int g = 1 ; g <= n ; g++) lista[g].push_back(g);
	for(int g = 0 ; g < m ; g++)
	{
		scanf("%d %d",&n1,&n2);
		check[n1] = true; check[n2] = true;
		lista[n1].push_back(n2); lista[n2].push_back(n1);
	}
	build(1,1,2*n); DFS_linearizacao(1);  DFS_processamento(1);
	for(int g = 1 ; g <= n ; g++) printf("%d ",resp[g]);
}


//besmellah
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
int st[maxn], ft[maxn], ans[maxn], mn[4 * maxn], t[4 * maxn], n, lazy[4 * maxn], T = -1;
vector <int> adj[maxn], vec[maxn];

void build(int id, int L, int R) {
	t[id] = R - L;
	if (R == L + 1) {
		return;
	}
	int mid = (L + R) / 2;
	build(2 * id + 0, L, mid);
	build(2 * id + 1, mid, R);
}

void relax(int id) {
	int x = lazy[id];
	lazy[id] = 0;
	mn[2 * id + 0] += x;
	lazy[2 * id + 0] += x;
	mn[2 * id + 1] += x;
	lazy[2 * id + 1] += x;
}

void add(int id, int L, int R, int l, int r, int x) {
	if (R <= l || r <= L)
		return;
	if (L >= l && R <= r) {
		mn[id] += x;
		lazy[id] += x;
//		cout << id << ' ' << mn[id] << ' ' << l << ' ' << r << endl;
		return;
	}
	int mid = (L + R) / 2;
	relax(id);
	add(2 * id + 0, L, mid, l, r, x);
	add(2 * id + 1, mid, R, l, r, x);
	mn[id] = min(mn[2 * id + 0], mn[2 * id + 1]);
	t[id] = 0;
	if (mn[id] == mn[2 * id + 0])
		t[id] += t[2 * id + 0];
	if (mn[id] == mn[2 * id + 1])
		t[id] += t[2 * id + 1];
}

void getst(int v, int p = -1) {
	st[v] = ++T;
	for (auto u: adj[v]) {
		if (u != p) {
			getst(u, v);
		}
	}
	ft[v] = T;
}

void dfs(int v, int p = -1) {
	for (auto u: vec[v]) {
		add(1, 0, n, st[v], ft[v] + 1, +1);
		add(1, 0, n, st[u], ft[u] + 1, +1);
	}
	if (mn[1]) {
		ans[v] = n - 1;
	}
	else {
		ans[v] = max(0, n - t[1] - 1);
	}
	for (auto u: adj[v]) {
		if (u != p) {
			dfs(u, v);
		}
	}
	for (auto u: vec[v]) {
		add(1, 0, n, st[v], ft[v] + 1, -1);
		add(1, 0, n, st[u], ft[u] + 1, -1);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	build(1, 0, n);
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	getst(0);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	dfs(0);
//	cout << st[0] << ' ' << ft[0] << endl;
	for (int i = 0; i < n; i++) {
		cout << ans[i] << ' ';
	}
}


//besmellah
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 5;
int st[maxn], ft[maxn], ans[maxn], mn[4 * maxn], t[4 * maxn], n, lazy[4 * maxn], T = -1;
vector <int> adj[maxn], vec[maxn];

void build(int id, int L, int R) {
	t[id] = R - L;
	if (R == L + 1) {
		return;
	}
	int mid = (L + R) / 2;
	build(2 * id + 0, L, mid);
	build(2 * id + 1, mid, R);
}

void relax(int id) {
	int x = lazy[id];
	lazy[id] = 0;
	mn[2 * id + 0] += x;
	mn[2 * id + 1] += x;
}

void add(int id, int L, int R, int l, int r, int x) {
	if (R <= l || r <= L)
		return;
	if (L >= l && R <= r) {
		mn[id] += x;
		lazy[id] += x;
		return;
	}
	int mid = (L + R) / 2;
	relax(id);
	add(2 * id + 0, L, mid, l, r, x);
	add(2 * id + 1, mid, R, l, r, x);
	mn[id] = min(mn[2 * id + 0], mn[2 * id + 1]);
	t[id] = 0;
	if (mn[id] == mn[2 * id + 0])
		t[id] += t[2 * id + 0];
	if (mn[id] == mn[2 * id + 1])
		t[id] += t[2 * id + 1];
}

void getst(int v, int p = -1) {
	st[v] = ++T;
	for (auto u: adj[v]) {
		if (u != p) {
			getst(u, v);
		}
	}
	ft[v] = T;
}

void dfs(int v, int p = -1) {
	for (auto u: vec[v]) {
		add(1, 0, n, st[v], ft[v] + 1, +1);
		add(1, 0, n, st[u], ft[u] + 1, +1);
	}
	if (mn[1]) {
		ans[v] = n;
	}
	else {
		ans[v] = max(0, n - t[1] - 1);
	}
	for (auto u: adj[v]) {
		if (u != p) {
			dfs(u, v);
		}
	}
	for (auto u: vec[v]) {
		add(1, 0, n, st[v], ft[v] + 1, -1);
		add(1, 0, n, st[u], ft[u] + 1, -1);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	build(1, 0, n);
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	getst(0);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	dfs(0);
	for (int i = 0; i < n; i++) {
		cout << ans[i] << ' ';
	}
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define INF 1000000000
#define LINF 1000000000000000000
#define N 100010
using namespace std;
ll n,m,ans[N],din[N],dout[N],cnt=0;
vector<ll> vt[N],con[N];
struct SegT{
	ll l,r,val,onum;
}segt[4*N];
void build_tree(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	segt[x].l=l;
	segt[x].r=r;
	segt[x].val=segt[x].onum=0;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,a=x<<1;
	build_tree(l,mid,a);
	build_tree(mid+1,r,a|1);
	return;
}
void update(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val++;
	}
	else
	{
		if(mid>=l)
		{
			update(l,r,a);
		}
		if(mid<r)
		{
			update(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void recall(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val--;
	}
	else
	{
		if(mid>=l)
		{
			recall(l,r,a);
		}
		if(mid<r)
		{
			recall(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void dfs(ll x,ll lst)
{
	ll i;
	din[x]=++cnt;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs(vt[x][i],x);
		}
	}
	dout[x]=cnt;
	return;
}
void dfs2(ll x,ll lst)
{
	ll i;
	for(i=0;i<con[x].size();i++)
	{
		update(din[con[x][i]],dout[con[x][i]],1);
	}
	ans[x]=max(segt[1].onum-1,(ll)0);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs2(vt[x][i],x);
		}
	}
	for(i=0;i<con[x].size();i++)
	{
		recall(din[con[x][i]],dout[con[x][i]],1);
	}
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	dfs(0,-1);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		con[x].push_back(x);
		con[x].push_back(y);
		con[y].push_back(x);
		con[y].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(con[i].begin(),con[i].end());
		con[i].erase(unique(con[i].begin(),con[i].end()),con[i].end());
	}
	build_tree(1,cnt,1);
	dfs2(0,-1);
	for(i=0;i<n;i++)
	{
		printf("%lld ",ans[i]);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,m,ans[N],din[N],dout[N],cnt=0;
vector<ll> vt[N],con[N];
struct SegT{
	ll l,r,mn,pd,num;
}segt[8*N];
void build_tree(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	segt[x].l=l;
	segt[x].r=r;
	segt[x].mn=segt[x].pd=0;
	segt[x].num=r-l+1;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,a=x<<1;
	build_tree(l,mid,a);
	build_tree(mid+1,r,a|1);
	return;
}
void push_down(ll x)
{
	ll a=x<<1;
	segt[x].mn+=segt[x].pd;
	segt[a].pd+=segt[x].pd;
	segt[a|1].pd+=segt[x].pd;
	segt[x].pd=0;
	return;
}
void update(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].pd++;
		return;
	}
	push_down(x);
	if(mid>=l)
	{
		update(l,r,a);
	}
	if(mid<r)
	{
		update(l,r,a|1);
	}
	segt[x].mn=min(segt[a].mn+segt[a].pd,segt[a|1].mn+segt[a|1].pd);
	segt[x].pd=0;
	segt[x].num=0;
	if(segt[x].mn==segt[a].mn+segt[a].pd)
	{
		segt[x].num+=segt[a].num;
	}
	if(segt[x].mn==segt[a|1].mn+segt[a|1].pd)
	{
		segt[x].num+=segt[a|1].num;
	}
	return;
}
void recall(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].pd--;
		return;
	}
	push_down(x);
	if(mid>=l)
	{
		recall(l,r,a);
	}
	if(mid<r)
	{
		recall(l,r,a|1);
	}
	segt[x].mn=min(segt[a].mn+segt[a].pd,segt[a|1].mn+segt[a|1].pd);
	segt[x].pd=0;
	segt[x].num=0;
	if(segt[x].mn==segt[a].mn+segt[a].pd)
	{
		segt[x].num+=segt[a].num;
	}
	if(segt[x].mn==segt[a|1].mn+segt[a|1].pd)
	{
		segt[x].num+=segt[a|1].num;
	}
	return;
}
void dfs(ll x,ll lst)
{
	ll i;
	din[x]=++cnt;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs(vt[x][i],x);
		}
	}
	dout[x]=cnt;
	return;
}
void dfs2(ll x,ll lst)
{
	ll i;
	for(i=0;i<con[x].size();i++)
	{
		update(din[con[x][i]],dout[con[x][i]],1);
	}
	ans[x]=n-1;
	if(segt[1].mn==0)
	{
		ans[x]-=segt[1].num;
	}
	ans[x]=max(ans[x],(ll)0);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs2(vt[x][i],x);
		}
	}
	for(i=0;i<con[x].size();i++)
	{
		recall(din[con[x][i]],dout[con[x][i]],1);
	}
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	dfs(0,-1);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		con[x].push_back(x);
		con[x].push_back(y);
		con[y].push_back(x);
		con[y].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(con[i].begin(),con[i].end());
		con[i].erase(unique(con[i].begin(),con[i].end()),con[i].end());
	}
	build_tree(1,cnt,1);
	dfs2(0,-1);
	for(i=0;i<n;i++)
	{
		printf("%lld ",ans[i]);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define INF 1000000000
#define LINF 1000000000000000000
#define N 100010
using namespace std;
ll n,m,ans[N],din[N],dout[N],cnt=0;
vector<ll> vt[N],con[N];
struct SegT{
	ll l,r,val,pd,onum;
}segt[8*N];
void build_tree(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	segt[x].l=l;
	segt[x].r=r;
	segt[x].val=segt[x].pd=segt[x].onum=0;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,a=x<<1;
	build_tree(l,mid,a);
	build_tree(mid+1,r,a|1);
	return;
}
void push_down(ll x)
{
	ll a=x<<1;
	segt[a].val+=segt[x].pd;
	segt[a|1].val+=segt[x].pd;
	segt[a].pd+=segt[x].pd;
	segt[a|1].pd+=segt[x].pd;
	segt[x].pd=0;
	return;
}
void update(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val++;
		segt[x].pd++;
		push_down(x);
	}
	else
	{
		push_down(x);
		if(mid>=l)
		{
			update(l,r,a);
		}
		if(mid<r)
		{
			update(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void recall(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val--;
		segt[x].pd--;
		push_down(x);
	}
	else
	{
		push_down(x);
		if(mid>=l)
		{
			recall(l,r,a);
		}
		if(mid<r)
		{
			recall(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void dfs(ll x,ll lst)
{
	ll i;
	din[x]=++cnt;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs(vt[x][i],x);
		}
	}
	dout[x]=cnt;
	return;
}
void dfs2(ll x,ll lst)
{
	ll i;
	for(i=0;i<con[x].size();i++)
	{
		update(din[con[x][i]],dout[con[x][i]],1);
	}
	ans[x]=max(segt[1].onum-1,(ll)0);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs2(vt[x][i],x);
		}
	}
	for(i=0;i<con[x].size();i++)
	{
		recall(din[con[x][i]],dout[con[x][i]],1);
	}
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	dfs(0,-1);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		con[x].push_back(x);
		con[x].push_back(y);
		con[y].push_back(x);
		con[y].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(con[i].begin(),con[i].end());
		con[i].erase(unique(con[i].begin(),con[i].end()),con[i].end());
	}
	build_tree(1,cnt,1);
	dfs2(0,-1);
	for(i=0;i<n;i++)
	{
		printf("%lld ",ans[i]);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define INF 1000000000
#define LINF 1000000000000000000
#define N 100010
using namespace std;
ll n,m,ans[N],din[N],dout[N],cnt=0;
vector<ll> vt[N],con[N];
struct SegT{
	ll l,r,val,onum;
}segt[8*N];
void build_tree(ll l,ll r,ll x)
{
	if(l>r)
	{
		return;
	}
	segt[x].l=l;
	segt[x].r=r;
	segt[x].val=segt[x].onum=0;
	if(l==r)
	{
		return;
	}
	ll mid=(l+r)>>1,a=x<<1;
	build_tree(l,mid,a);
	build_tree(mid+1,r,a|1);
	return;
}
void update(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val++;
	}
	else
	{
		if(mid>=l)
		{
			update(l,r,a);
		}
		if(mid<r)
		{
			update(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void recall(ll l,ll r,ll x)
{
	ll tl=segt[x].l,tr=segt[x].r;
	ll mid=(tl+tr)>>1,a=x<<1;
	if(tl>r||tr<l)
	{
		return;
	}
	if(l<=tl&&tr<=r)
	{
		segt[x].val--;
	}
	else
	{
		if(mid>=l)
		{
			recall(l,r,a);
		}
		if(mid<r)
		{
			recall(l,r,a|1);
		}
	}
	if(segt[x].val)
	{
		segt[x].onum=tr-tl+1;
	}
	else
	{
		segt[x].onum=segt[a].onum+segt[a|1].onum;
	}
	return;
}
void dfs(ll x,ll lst)
{
	ll i;
	din[x]=++cnt;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs(vt[x][i],x);
		}
	}
	dout[x]=cnt;
	return;
}
void dfs2(ll x,ll lst)
{
	ll i;
	for(i=0;i<con[x].size();i++)
	{
		update(din[con[x][i]],dout[con[x][i]],1);
	}
	ans[x]=max(segt[1].onum-1,(ll)0);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs2(vt[x][i],x);
		}
	}
	for(i=0;i<con[x].size();i++)
	{
		recall(din[con[x][i]],dout[con[x][i]],1);
	}
	return;
}
int main(){
	ll i,x,y;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	dfs(0,-1);
	for(i=0;i<m;i++)
	{
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		con[x].push_back(x);
		con[x].push_back(y);
		con[y].push_back(x);
		con[y].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(con[i].begin(),con[i].end());
		con[i].erase(unique(con[i].begin(),con[i].end()),con[i].end());
	}
	build_tree(1,cnt,1);
	dfs2(0,-1);
	for(i=0;i<n;i++)
	{
		printf("%lld ",ans[i]);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 10;

int n, open[N], close[N], mytime, ans[N], cnt[N], m, u, v, lazy[4 * N];
pair <int, int> tree[4 * N];
vector <int> node[N];
stack <int> s[N], st;
bool mark[N];

void build (int b, int e, int idx) {
    if (b + 1 == e) {
        tree[idx].second = 1;
        return;
    }
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    build (b, mid, lidx);
    build (mid, e, ridx);
    tree[idx].second = tree[lidx].second + tree[ridx].second;
}

void update (int b, int e, int l, int r, int val, int idx) {
    if (b >= r || e <= l)
        return;
    if (b >= l && e <= r) {
        lazy[idx] += val;
        tree[idx].first += val;
        return;
    }
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    update (b, mid, l, r, val, lidx);
    update (mid, e, l, r, val, ridx);
    if (tree[lidx].first == tree[ridx].first)
        tree[idx] = {tree[lidx].first, tree[ridx].second + tree[lidx].second};
    else if (tree[lidx].first < tree[ridx].first)
        tree[idx] = tree[lidx];
    else
        tree[idx] = tree[ridx];
    tree[idx].first += lazy[idx];
}

pair <int, int> query (int b, int e, int l, int r, int idx) {
    //cout << b << ' ' << e << ' ' << l << ' ' << r << ' ' << endl;
    if (b >= r || e <= l)
        return {N * 10, N * 10};
    if (b >= l && e <= r)
        return {tree[idx].first, tree[idx].second};
    int mid = (b + e) >> 1,
                lidx = idx << 1, ridx = lidx | 1;
    pair <int, int> lchild = query (b, mid, l, r, lidx),
                        rchild = query (mid, e, l, r, ridx);
    if (lchild.first == rchild.first)
        return {lchild.first + lazy[idx], lchild.second + rchild.second};
    else if (lchild.first < rchild.first)
        return {lchild.first + lazy[idx], lchild.second};
    return {rchild.first + lazy[idx], rchild.second};
}

void dfs (int v) {
    mark[v] = true;
    open[v] = mytime++;
    for (auto i : node[v])
        if (!mark[i])
            dfs (i);
    close[v] = mytime;
}

void func (int v) {
    mark[v] = true;
    while (!s[v].empty()) {
        st.push(s[v].top());
        update (0, n, open[v], close[v], 1, 1);
        update (0, n, open[s[v].top()], close[s[v].top()], 1, 1);
        s[v].pop();
    }
    pair <int, int> a1 = query (0, n, 0, open[v], 1),
                        a2 = query (0, n, open[v] + 1, n, 1);
    ans[v] = n - 1;
    //cout << "HI " << v << ' ' << a1.first << ' ' << a1.second << "...." << a2.first << ' ' << a2.second << endl;
    if (!a1.first)
        ans[v] -= a1.second;
    if (!a2.first)
        ans[v] -= a2.second;
    for (auto i : node[v])
        if (!mark[i])
            func (i);
    while (cnt[v]--) {
        update (0, n, open[v], close[v], -1, 1);
        update (0, n, open[st.top()], close[st.top()], -1, 1);
        st.pop();
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    build (0, n, 1);
    dfs (1);
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        s[u].push(v);
        s[v].push(u);
        cnt[v]++;
        cnt[u]++;
    }
    memset (mark, 0, sizeof(mark));
    func (1);
    //for (int i = 1; i <= n; i++)
    //    cout << i << " : " << open[i] << ' ' << close[i] << endl;
    for (int i = 1; i <= n; i++)
        cout << ans[i] << ' ';
    cout << '\n';
    return 0;
}


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

const int maxn=1e5+10;

vector <int> g[maxn],add[maxn];
int n,m;

class SegmentTree{
public:
	int tree[maxn],tag[maxn];
	void push_up(int x,int l,int r){
		if(tag[x]>0) tree[x]=r-l+1;
		else{
			if(l==r) tree[x]=0;
			else tree[x]=tree[x<<1]+tree[x<<1|1];
		}
	}
	void update(int x,int l,int r,int cl,int cr,int val){
		if(cr<l||r<cl) return;
		if(cl<=l&&r<=cr){
			tag[x]+=val;
			push_up(x,l,r);
			return;
		}
		int mid=(l+r)>>1;
		update(x<<1,l,mid,cl,cr,val);
		update(x<<1|1,mid+1,r,cl,cr,val);
		push_up(x,l,r);
	}
}seg;

int l[maxn],r[maxn],t=0,ans[maxn];

void dfs(int x,int pa){
	l[x]=r[x]=t++;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==pa) continue;
		dfs(to,x);
		r[x]=r[to];
	}
}

void get_ans(int x,int pa){
	for(int i=0;i<add[x].size();i++){
		int id=add[x][i];
		seg.update(1,0,n-1,l[id],r[id],1);
	}
	ans[x]=seg.tree[1];
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==pa) continue;
		get_ans(to,x);
	}
	for(int i=0;i<add[x].size();i++){
		int id=add[x][i];
		seg.update(1,0,n-1,l[id],r[id],-1);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
//	for(int i=0;i<n;i++) printf("%d,%d ",l[i],r[i]); printf("\n");
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		add[u].push_back(v); add[v].push_back(v);
		add[v].push_back(u); add[u].push_back(u);
	}
	get_ans(0,-1);
	for(int i=0;i<n;i++) printf("%d ",ans[i]==0?0:ans[i]-1);
	printf("\n");
	return 0;
}


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

const int maxn=1e5+10;

vector <int> g[maxn],add[maxn];
int n,m;

class SegmentTree{
public:
	int tree[maxn*4],tag[maxn*4];
	void push_up(int x,int l,int r){
		if(tag[x]>0) tree[x]=r-l+1;
		else{
			if(l==r) tree[x]=0;
			else tree[x]=tree[x<<1]+tree[x<<1|1];
		}
	}
	void update(int x,int l,int r,int cl,int cr,int val){
		if(cr<l||r<cl) return;
		if(cl<=l&&r<=cr){
			tag[x]+=val;
			push_up(x,l,r);
			return;
		}
		int mid=(l+r)>>1;
		update(x<<1,l,mid,cl,cr,val);
		update(x<<1|1,mid+1,r,cl,cr,val);
		push_up(x,l,r);
	}
}seg;

int l[maxn],r[maxn],t=0,ans[maxn];

void dfs(int x,int pa){
	l[x]=r[x]=t++;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==pa) continue;
		dfs(to,x);
		r[x]=r[to];
	}
}

void get_ans(int x,int pa){
	for(int i=0;i<add[x].size();i++){
		int id=add[x][i];
		seg.update(1,0,n-1,l[id],r[id],1);
	}
	ans[x]=seg.tree[1];
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==pa) continue;
		get_ans(to,x);
	}
	for(int i=0;i<add[x].size();i++){
		int id=add[x][i];
		seg.update(1,0,n-1,l[id],r[id],-1);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
//	for(int i=0;i<n;i++) printf("%d,%d ",l[i],r[i]); printf("\n");
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		add[u].push_back(v); add[v].push_back(v);
		add[v].push_back(u); add[u].push_back(u);
	}
	get_ans(0,-1);
	for(int i=0;i<n;i++) printf("%d ",ans[i]==0?0:ans[i]-1);
	printf("\n");
	return 0;
}


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

const int maxn=1e5+10;

class Block{
public:
	int tag,sum; vector <int> v;
	int get_res(){
		int low=0,high=(int)v.size(),res=(int)v.size();
		while(low<high){
			int mid=(low+high)>>1;
			if(v[mid]>-tag) high=mid,res=min(res,mid);
			else low=mid+1;
		}
		return (int)v.size()-res;
	}
}block[500];

vector <int> g[maxn],add[maxn],del[maxn],track;
int L[maxn],R[maxn],a[maxn],cur_pos=0;
int n,m,cnt=0,s=0;
int ans[maxn];

void dfs(int x,int pa){
	L[x]=R[x]=cur_pos++;
	track.push_back(x);
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to==pa) continue;
		dfs(to,x);
		L[x]=min(L[x],L[to]);
		R[x]=max(R[x],R[to]);
	}
}

void change(int id){
	Block &tmp=block[id];
	tmp.tag=0; cnt-=tmp.sum; tmp.v.clear();
	for(int i=id*s;i<min(id*s+s,n);i++) tmp.v.push_back(a[i]);
	sort(tmp.v.begin(),tmp.v.end());
	tmp.sum=tmp.get_res(); cnt+=tmp.sum;
}

void update(int l,int r,int val){
	if(l/s==r/s){
		Block &tmp=block[l/s];
		for(int i=l/s*s;i<min(l/s*s+s,n);i++) a[i]+=tmp.tag;
		for(int i=l;i<=r;i++) a[i]+=val; change(l/s);
		return;
	}
	for(int i=l/s+1;i<r/s;i++){
		Block &tmp=block[i]; cnt-=tmp.sum; tmp.tag+=val;
		tmp.sum=tmp.get_res(); cnt+=tmp.sum;
	}
	for(int i=l/s*s;i<min(l/s*s+s,n);i++) a[i]+=block[l/s].tag;
	for(int i=l;i<min(l/s*s+s,n);i++) a[i]+=val; change(l/s);
	for(int i=r/s*s;i<min(r/s*s+s,n);i++) a[i]+=block[r/s].tag;
	for(int i=r/s*s;i<=r;i++) a[i]+=val; change(r/s);
}

int main(){
//	freopen("b.in","r",stdin);
//	freopen("b.out","w",stdout);
	for(int i=0;i<500;i++) block[i].sum=block[i].tag=0;
	for(int i=0;i<500;i++) block[i].v.clear();
	scanf("%d%d",&n,&m);
	while(s*s<=n) s++;
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0,-1);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		add[L[u]].push_back(v); del[R[u]].push_back(v);
		add[L[v]].push_back(v); del[R[v]].push_back(v);
		add[L[v]].push_back(u); del[R[v]].push_back(u);
		add[L[u]].push_back(u); del[R[u]].push_back(u);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<add[i].size();j++) update(L[add[i][j]],R[add[i][j]],+1);
		Block tmp=block[i/s];
		if(a[i]+tmp.tag>0) ans[track[i]]=cnt-1;
		else ans[track[i]]=cnt;
		for(int j=0;j<del[i].size();j++) update(L[del[i][j]],R[del[i][j]],-1);
	}
	for(int i=0;i<n;i++) printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

/*
5 1
1 2
1 3
3 5
3 4
2 3
*/

/*
11 3
1 2
2 3
2 4
1 5
5 6
5 7
5 8
6 9
8 10
8 11
2 9
3 6
2 8
*/

/*
11 3
1 5
5 3
5 10
1 8
8 11
8 6
8 4
6 2
4 9
4 7
5 2
3 6
5 4
*/

/*
11 6
1 2
2 3
2 4
1 5
5 6
5 7
5 8
6 9
8 10
8 11
4 3
3 7
7 9
9 10
10 11
9 2
*/


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define vp  vector<pii>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define sf scanf
#define pf printf
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 INT128;
//INT128 read(){
//    INT128 x=0,f=1;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
//    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
//    return x*f;
//}
//void write(INT128 x){
//    if(x<0){putchar('-');x=-x;}
//    if(x<10){putchar(x+'0'); return;}
//    write(x/10);putchar(x%10+'0');
//}
typedef long double ld;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int MAXN=1e5+5;
const int MAXM=2e6+5;
const int MOD=1e9+7;
int sgn(double x){if(fabs(x)<eps)return 0;if(x<0)return -1;else return 1;}
ll pw(ll a,ll n,ll mod){ll ret=1;while(n){if(n&1)ret=ret*a%mod;a=a*a%mod;n>>=1;}return ret;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
//head

int n,m,tim,L[MAXN],R[MAXN],ans[MAXN];
vi G[MAXN],q[MAXN];

//Tree
int sum[MAXN<<2],lz[MAXN<<2],cov[MAXN<<2];

void up(int l,int r,int rt){
    if(sum[rt])cov[rt]=r-l+1;
    else if(l!=r)cov[rt]=cov[rt<<1]+cov[rt<<1|1];
    else cov[rt]=0;
}

void down(int l,int r,int rt){
    if(lz[rt]){
        sum[rt<<1]+=lz[rt];
        sum[rt<<1|1]+=lz[rt];
        lz[rt<<1]+=lz[rt];
        lz[rt<<1|1]+=lz[rt];
        lz[rt]=0;
        //up
        int mid=l+r>>1;
        up(ls); up(rs);
    }
}

void upd(int L,int R,int v,int l,int r,int rt){
    if(L<=l&&r<=R){
        sum[rt]+=v;
        lz[rt]+=v;
        //need
        if(l!=r)down(l,r,rt);
        up(l,r,rt);
        return;
    }
    down(l,r,rt);
    int mid=l+r>>1;
    if(L<=mid)upd(L,R,v,ls);
    if(R>mid)upd(L,R,v,rs);
    up(l,r,rt);
}

//Main
void dfs1(int u,int f){
    L[u]=++tim;
    for(auto v:G[u]){
        if(v!=f)dfs1(v,u);
    }
    R[u]=tim;
}

void dfs2(int u,int f){
    for(auto o:q[u]){
        upd(L[o],R[o],1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],1,1,n,1);
    }
    ans[u]=cov[1]; if(ans[u])ans[u]--;
    for(auto v:G[u]){
        if(v!=f)dfs2(v,u);
    }
    for(auto o:q[u]){
        upd(L[o],R[o],-1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],-1,1,n,1);
    }
}

int main(){
    sf("%d%d",&n,&m);
    int u,v;
    rep(i,1,n){
        sf("%d%d",&u,&v);
        G[u].pb(v); G[v].pb(u);
    }
    tim=0; dfs1(1,-1);
    rep(i,1,m+1){
        sf("%d%d",&u,&v);
        q[u].pb(v); q[v].pb(u);
    }
    dfs2(1,-1);
    rep(i,1,n+1)pf("%d ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define vp  vector<pii>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define sf scanf
#define pf printf
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 INT128;
//INT128 read(){
//    INT128 x=0,f=1;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
//    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
//    return x*f;
//}
//void write(INT128 x){
//    if(x<0){putchar('-');x=-x;}
//    if(x<10){putchar(x+'0'); return;}
//    write(x/10);putchar(x%10+'0');
//}
typedef long double ld;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int MAXN=1e5+5;
const int MAXM=2e6+5;
const int MOD=1e9+7;
int sgn(double x){if(fabs(x)<eps)return 0;if(x<0)return -1;else return 1;}
ll pw(ll a,ll n,ll mod){ll ret=1;while(n){if(n&1)ret=ret*a%mod;a=a*a%mod;n>>=1;}return ret;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
//head

int n,m,tim,L[MAXN],R[MAXN],ans[MAXN];
vi G[MAXN],q[MAXN];

//Tree
int sum[MAXN<<2],cov[MAXN<<2];

void up(int l,int r,int rt){
    if(sum[rt])cov[rt]=r-l+1;
    else if(l!=r)cov[rt]=cov[rt<<1]+cov[rt<<1|1];
    else cov[rt]=0;
}

void upd(int L,int R,int v,int l,int r,int rt){
    if(L<=l&&r<=R){
        sum[rt]+=v;
        up(l,r,rt);
        return;
    }
    int mid=l+r>>1;
    if(L<=mid)upd(L,R,v,ls);
    if(R>mid)upd(L,R,v,rs);
    up(l,r,rt);
}

//Main
void dfs1(int u,int f){
    L[u]=++tim;
    for(auto v:G[u]){
        if(v!=f)dfs1(v,u);
    }
    R[u]=tim;
}

void dfs2(int u,int f){
    for(auto o:q[u]){
        upd(L[o],R[o],1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],1,1,n,1);
    }
    ans[u]=cov[1]; if(ans[u])ans[u]--;
    for(auto v:G[u]){
        if(v!=f)dfs2(v,u);
    }
    for(auto o:q[u]){
        upd(L[o],R[o],-1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],-1,1,n,1);
    }
}

int main(){
    sf("%d%d",&n,&m);
    int u,v;
    rep(i,1,n){
        sf("%d%d",&u,&v);
        G[u].pb(v); G[v].pb(u);
    }
    tim=0; dfs1(1,-1);
    rep(i,1,m+1){
        sf("%d%d",&u,&v);
        q[u].pb(v); q[v].pb(u);
    }
    dfs2(1,-1);
    rep(i,1,n+1)pf("%d ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define vp  vector<pii>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define sf scanf
#define pf printf
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 INT128;
//INT128 read(){
//    INT128 x=0,f=1;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
//    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
//    return x*f;
//}
//void write(INT128 x){
//    if(x<0){putchar('-');x=-x;}
//    if(x<10){putchar(x+'0'); return;}
//    write(x/10);putchar(x%10+'0');
//}
typedef long double ld;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int MAXN=1e5+5;
const int MAXM=2e6+5;
const int MOD=1e9+7;
int sgn(double x){if(fabs(x)<eps)return 0;if(x<0)return -1;else return 1;}
ll pw(ll a,ll n,ll mod){ll ret=1;while(n){if(n&1)ret=ret*a%mod;a=a*a%mod;n>>=1;}return ret;}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
//head

int n,m,tim,L[MAXN],R[MAXN],ans[MAXN];
vi G[MAXN],q[MAXN];

//Tree
int sum[MAXN<<2],lz[MAXN<<2],cov[MAXN<<2];

void up(int l,int r,int rt){
    if(sum[rt])cov[rt]=r-l+1;
    else if(l!=r)cov[rt]=cov[rt<<1]+cov[rt<<1|1];
    else cov[rt]=0;
}

void down(int l,int r,int rt){
    if(lz[rt]){
        sum[rt<<1]+=lz[rt];
        sum[rt<<1|1]+=lz[rt];
        lz[rt<<1]+=lz[rt];
        lz[rt<<1|1]+=lz[rt];
        lz[rt]=0;
        //up
        int mid=l+r>>1;
        up(ls); up(rs);
    }
}

void upd(int L,int R,int v,int l,int r,int rt){
    if(L<=l&&r<=R){
        sum[rt]+=v;
        lz[rt]+=v;
        //need
        down(l,r,rt);
        up(l,r,rt);
        return;
    }
    down(l,r,rt);
    int mid=l+r>>1;
    if(L<=mid)upd(L,R,v,ls);
    if(R>mid)upd(L,R,v,rs);
    up(l,r,rt);
}

//Main
void dfs1(int u,int f){
    L[u]=++tim;
    for(auto v:G[u]){
        if(v!=f)dfs1(v,u);
    }
    R[u]=tim;
}

void dfs2(int u,int f){
    for(auto o:q[u]){
        upd(L[o],R[o],1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],1,1,n,1);
    }
    ans[u]+=cov[1]; if(ans[u])ans[u]--;
    for(auto v:G[u]){
        if(v!=f)dfs2(v,u);
    }
    for(auto o:q[u]){
        upd(L[o],R[o],-1,1,n,1);
    }
    if(!q[u].empty()){
        upd(L[u],R[u],-1,1,n,1);
    }
}

int main(){
    sf("%d%d",&n,&m);
    int u,v;
    rep(i,1,n){
        sf("%d%d",&u,&v);
        G[u].pb(v); G[v].pb(u);
    }
    tim=0; dfs1(1,-1);
    rep(i,1,m+1){
        sf("%d%d",&u,&v);
        q[u].pb(v); q[v].pb(u);
    }
    dfs2(1,-1);
    rep(i,1,n+1)pf("%d ",ans[i]);
}


# include <bits/stdc++.h>
/// my holy template
# define F first
# define S second
# define mp make_pair
# define pii pair<int,int>
/// eveything goes according to my plan
# define long long long
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
struct node {
  int mn;
  int add;
  int cnt;
  node() {
    mn = add = cnt = 0;
  }
};

struct segtree {
  int n;
  vec<node> t;

  segtree (int n) : n(n), t(4*n + 1) {build (1, 1, n);}

  void build (int v, int tl, int tr) {
    if (tl == tr) {
      t[v].cnt = 1;
      return;
    }
    int tmid = (tl+tr) >> 1;
    t[v].cnt = (tr - tl + 1);
    build (2*v, tl, tmid);
    build (2*v + 1, tmid + 1, tr);
  }

  void recalc (int v) {
    int x = min (t[2*v].mn, t[2*v + 1].mn);
    t[v].mn = x;
    t[v].cnt = 0;
    if (x == t[2*v].mn)
      t[v].cnt = t[2*v].cnt;
    if (x == t[2*v + 1].mn)
      t[v].cnt += t[2*v + 1].cnt;
  }
  void push (int v, bool leaf) {
    if (t[v].add) {
      t[v].mn += t[v].add;
      if (!leaf) {
        t[2*v].add += t[v].add;
        t[2*v + 1].add += t[v].add;
      }
      t[v].add = 0;
    }
  }

  void update (int v, int tl, int tr, int l, int r, int x) {
    push (v, tl == tr);
    if (tl > r || tr < l) return;
    if (l <= tl && tr <= r) {
      t[v].add += x;
      push (v, tl == tr);
      return;
    }
    int tmid = (tl+tr) >> 1;
    update (2*v, tl, tmid, l, r, x);
    update (2*v + 1, tmid + 1, tr, l, r, x);
    recalc (v);
  }
  int get (int v, int tl, int tr, int l, int r) {
    push (v, tl == tr);
    if (tr < l || tl > r) return 0;
    if (l <= tl && tr <= r)
      return (t[v].mn == 0 ? t[v].cnt : 0);
    int tmid = (tl+tr) >> 1;
    return get (2*v, tl, tmid, l, r) + get (2*v + 1, tmid + 1, tr, l, r);
  }
  int get (int l, int r) {
    return get (1, 1, n, l, r);
  }

  void update (int l, int r, int x) {
    if (l <= r)
      update (1, 1, n, l, r, x);
  }
  segtree() {}
} T;

int tin[Sz], tout[Sz], timer;

vec<pii> c[Sz];

vec<int> g[Sz];

int ans[Sz];

int n, m;

void pre_dfs (int v, int pr) {
  tin[v] = ++timer;
  for (int to : g[v]) {
    if (to != pr)
      pre_dfs (to, v);
  }
  tout[v] = timer;
}

void calc (int v, int pr) {
  for (auto x : c[v])
    T.update (x.F, x.S, +1);
  ans[v] = n - T.get (1, n) - !T.get (tin[v], tin[v]);

  for (int to : g[v]) {
    if (to != pr)
      calc (to, v);
  }
  for (auto x : c[v])
    T.update (x.F, x.S, -1);
}
int main()
{
  scanf ("%d %d", &n,&m);
  for (int i = 1; i <= n-1; i++) {
    int x, y; scanf ("%d %d", &x, &y);
    g[x].pb (y);
    g[y].pb (x);
  }
  pre_dfs (1, 1);
  for (int i = 1; i <= m; i++) {
    int a, b; scanf ("%d %d", &a, &b);
    c[a].pb ({tin[a], tout[a]});
    c[b].pb ({tin[b], tout[b]});
    c[b].pb ({tin[a], tout[a]});
    c[a].pb ({tin[b], tout[b]});
  }
  T = segtree(n);
  calc (1, 1);
  for (int i = 1; i <= n; i++)
    printf ("%d ", ans[i]);

  return 0;
}

// Coded by Z...


# include <bits/stdc++.h>
/// my holy template
# define F first
# define S second
# define mp make_pair
# define pii pair<int,int>
/// eveything goes according to my plan
# define long long long
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
struct node {
  int mn;
  int add;
  int cnt;
  node() {
    mn = add = cnt = 0;
  }
};

struct segtree {
  int n;
  vec<node> t;

  segtree (int n) : n(n), t(4*n + 1) {build (1, 1, n);}

  void build (int v, int tl, int tr) {
    if (tl == tr) {
      t[v].cnt = 1;
      return;
    }
    int tmid = (tl+tr) >> 1;
    t[v].cnt = (tr - tl + 1);
    build (2*v, tl, tmid);
    build (2*v + 1, tmid + 1, tr);
  }

  void recalc (int v) {
    int x = min (t[2*v].mn, t[2*v + 1].mn);
    t[v].mn = x;
    t[v].cnt = 0;
    if (x == t[2*v].mn)
      t[v].cnt = t[2*v].cnt;
    if (x == t[2*v + 1].mn)
      t[v].cnt += t[2*v + 1].cnt;
  }
  void push (int v, bool leaf) {
    if (t[v].add) {
      t[v].mn += t[v].add;
      if (!leaf) {
        t[2*v].add += t[v].add;
        t[2*v + 1].add += t[v].add;
      }
      t[v].add = 0;
    }
  }

  void update (int v, int tl, int tr, int l, int r, int x) {
    push (v, tl == tr);
    if (tl > r || tr < l) return;
    if (l <= tl && tr <= r) {
      t[v].add += x;
      push (v, tl == tr);
      return;
    }
    int tmid = (tl+tr) >> 1;
    update (2*v, tl, tmid, l, r, x);
    update (2*v + 1, tmid + 1, tr, l, r, x);
    recalc (v);
  }
  int get (int v, int tl, int tr, int l, int r) {
    push (v, tl == tr);
    if (tr < l || tl > r) return 0;
    if (l <= tl && tr <= r)
      return (t[v].mn == 0 ? t[v].cnt : 0);
    int tmid = (tl+tr) >> 1;
    return get (2*v, tl, tmid, l, r) + get (2*v + 1, tmid + 1, tr, l, r);
  }
  int get (int l, int r) {
    return get (1, 1, n, l, r);
  }

  void update (int l, int r, int x) {
    if (l <= r)
      update (1, 1, n, l, r, x);
  }
  segtree() {}
} T;

int tin[Sz], tout[Sz], timer;

vec<pii> c[Sz];

vec<int> g[Sz];

int ans[Sz];

int n, m;

void pre_dfs (int v, int pr) {
  tin[v] = ++timer;
  for (int to : g[v]) {
    if (to != pr)
      pre_dfs (to, v);
  }
  tout[v] = timer;
}

void calc (int v, int pr) {
  for (auto x : c[v])
    T.update (x.F, x.S, +1);
  ans[v] = n - T.get (1, n) - !T.get (tin[v], tin[v]);

  for (int to : g[v]) {
    if (to != pr)
      calc (to, v);
  }
  for (auto x : c[v])
    T.update (x.F, x.S, -1);
}
int main()
{
  scanf ("%d %d", &n,&m);
  for (int i = 1; i <= n-1; i++) {
    int x, y; scanf ("%d %d", &x, &y);
    g[x].pb (y);
    g[y].pb (x);
  }
  pre_dfs (1, 1);
  for (int i = 1; i <= m; i++) {
    int a, b; scanf ("%d %d", &a, &b);
    c[a].pb ({tin[a], tout[a]});
    c[b].pb ({tin[b], tout[b]});
    c[b].pb ({tin[a], tout[a]});
    c[a].pb ({tin[b], tout[b]});
  }
  T = segtree(n);
  calc (1, 1);
  for (int i = 1; i <= n; i++)
    cout << ans[i] << ' ';

  return 0;
}

// Coded by Z...


#include <iostream>
#include <vector>

using namespace std;

const int maxn = 100 * 100 * 10 + 10;
int lazy[maxn * 4], minn[maxn * 4], cnt[maxn * 4],  ans[maxn], f[maxn], st[maxn], t;
bool mark[maxn], flag;
vector <int> adj[maxn];
vector <pair <int , int > > q[maxn];
int n, m, x, y1, y2;

void shift(int b , int e, int ind)
{
	lazy[ind * 2] += lazy[ind];
	lazy[ind * 2 + 1] += lazy[ind];
	minn[ind * 2] += lazy[ind];
	minn[ind * 2 + 1] += lazy[ind];
	lazy[ind] = 0;
}

void add(int l , int r , int val , int ind , int b , int e)
{
	if (l <= b && e <= r )
	{
		minn[ind] += val;
		lazy[ind] +=val;
		//cout << b << " " << e << " " << cnt[ind] << endl;
		return;
	}
	shift(b , e , ind);
	int mid = (b + e) / 2;
	if (l < mid)
		add(l , r, val , ind  * 2, b , mid);
	if (r > mid)
		add(l , r , val , ind * 2 + 1 , mid, e);
	minn[ind] = min(minn[ind * 2], minn[ind * 2 + 1]);
	if (minn[ind * 2] == minn[ind * 2 + 1])
		cnt[ind] = cnt[ind * 2] + cnt[ind * 2 + 1];
	else if (minn[ind * 2] < minn[ind * 2 + 1])
		cnt[ind] = cnt[ind * 2];
	else
		cnt[ind] = cnt[ind * 2 + 1];
	//cout << b << " " << e << " " << cnt[ind] << endl;
	return ;
}

void dfs(int v)
{
	if (!flag)
	{
		st[v] = t;
		t++;
	}
	mark[v] = 1;
	if (flag)
	{
		//	cout << "*****  " << cnt[1] << endl;;
		for (int i = 0; i < (int)q[v].size() ; i ++)
		{
			//cout << cnt[1] << "\n" << q[v][i].first << " " << q[v][i].second << "\n";
			add(q[v][i].first, q[v][i].second , 1 , 1 , 0 , n);
			//cout << cnt[1] << "\n";
		}
		if (minn[1] == 0 )
			ans[v] = n - cnt[1];
		else
			ans[v] = n;
		//cout << "in if" << v << " " << ans[v] << endl;
	}
	for (int i = 0; i < (int)adj[v].size(); i ++)
		if (!mark[adj[v][i]])
			dfs(adj[v][i]);
	if (flag)
	{
		for (int i = 0; i < (int)q[v].size() ; i ++)
		{
			//cout << cnt[1] << "\n" << q[v][i].first << " " << q[v][i].second << "\n";
			add(q[v][i].first, q[v][i].second , -1 , 1 , 0 , n);
			//cout << cnt[1] << "\n";
		}
		//cout << "###  " << cnt[1] << endl;
	}
	if (!flag)
	f[v] = t;
}

void make(int b , int e , int ind)
{
	if (e - b == 1)
	{
		cnt[ind] = 1;
		return;
	}
	int mid = (b + e) / 2;
	make(b, mid , ind * 2);
	make(mid , e , ind * 2 + 1);
	cnt[ind] = cnt[ind * 2 ] + cnt[ind * 2 + 1];
	return ;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n - 1; i ++)
	{
		cin >> x >> y1;
		x--; y1--;
		adj[x].push_back(y1);
		adj[y1].push_back(x);
	}
	dfs(0);
	for (int i=0; i<n; i++)
		//cout << i << " " << st[i] << " " << f[i] << "\n";
	flag = 1;
	t = 0;
	for (int i = 0; i < n; i ++)
		mark[i] = 0;
	make(0 , n , 1);
	cout << endl;
	for (int i = 0; i < m; i ++)
	{
		cin >> x >> y1;
		x --; y1 --;
		if (st[x] > st[y1])
			swap(x , y1);
		if (f[x] >= f[y1])
			q[x].push_back(make_pair(st[x], f[x] ));
		else
		{
			// f + 1????
			q[x].push_back(make_pair(st[y1], f[y1] ));
			q[x].push_back(make_pair(st[x], f[x] ));
			q[y1].push_back(make_pair(st[x], f[x]));
			q[y1].push_back(make_pair(st[y1], f[y1] ));
		}
	}
	dfs(0);
	for (int i = 0; i < n; i ++)
		cout << max(ans[i] - 1  , 0) << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define P pair<int,int>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
struct Edge
{
	int to,next;
}edge[maxn<<1];
int head[maxn],tot;
void addedge(int u,int v)
{
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
vector<P>op[maxn];
int tim;
int in[maxn],out[maxn];
int n,m;
void dfs1(int u,int pre)
{
	in[u]=++tim;
	op[u].clear();
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs1(v,u);
	}
	out[u]=tim;
}
int ans[maxn];
int mn[maxn<<2],addv[maxn<<2],sum[maxn<<2];
void maintain(int o,int l,int r,int val)
{
	addv[o]+=val;
	mn[o]+=val;
	if(mn[o]>0) sum[o]=r-l+1;
	else if(l==r) sum[o]=0;
	else sum[o]=sum[lc]+sum[rc];
}
void down(int o,int l,int r)
{
	if(addv[o]!=0)
	{
		maintain(lc,l,mid,addv[o]);
		maintain(rc,mid+1,r,addv[o]);
		addv[o]=0;
	}
}
void up(int o)
{
	mn[o]=min(mn[lc],mn[rc]);
	sum[o]=sum[lc]+sum[rc];
}
void update(int o,int l,int r,int y1,int y2,int val)
{
	if(y1<=l&&y2>=r)
	{
		maintain(o,l,r,val);
		return;
	}
	down(o,l,r);
	if(y1<=mid) update(lc,l,mid,y1,y2,val);
	if(y2>mid) update(rc,mid+1,r,y1,y2,val);
	maintain(o,l,r,0);
}
void dfs2(int u,int pre)
{
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,1);
	ans[u]=max(0,sum[1]-1);
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs2(v,u);
	}
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,-1);
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		int u,v;
		for(int i=1;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			addedge(u,v);
			addedge(v,u);
		}
		tim=0;
		dfs1(1,-1);
		while(m--)
		{
			scanf("%d%d",&u,&v);
			op[u].push_back(P(in[v],out[v]));
			op[u].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[v],out[v]));
		}
		memset(mn,0,sizeof(mn));
		memset(ans,0,sizeof(ans));
		memset(addv,0,sizeof(addv));
		dfs2(1,-1);
		for(int i=1;i<=n;++i)
			printf("%d%c",ans[i],i==n?'\n':' ');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define P pair<int,int>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
struct Edge
{
	int to,next;
}edge[maxn<<1];
int head[maxn],tot;
void addedge(int u,int v)
{
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
vector<P>op[maxn];
int tim;
int in[maxn],out[maxn];
int n,m;
void dfs1(int u,int pre)
{
	in[u]=++tim;
	op[u].clear();
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs1(v,u);
	}
	out[u]=tim;
}
int ans[maxn];
int mn[maxn<<2],addv[maxn<<2],sum[maxn<<2];
void maintain(int o,int l,int r,int val)
{
	addv[o]+=val;
	mn[o]+=val;
	if(mn[o]>0) sum[o]=r-l+1;
	else if(l==r) sum[o]=0;
	else sum[o]=sum[lc]+sum[rc];
}
void down(int o,int l,int r)
{
	if(addv[o]!=0)
	{
		maintain(lc,l,mid,addv[o]);
		maintain(rc,mid+1,r,addv[o]);
		addv[o]=0;
	}
}
void up(int o)
{
	mn[o]=min(mn[lc],mn[rc]);
	sum[o]=sum[lc]+sum[rc];
}
void update(int o,int l,int r,int y1,int y2,int val)
{
	if(y1<=l&&y2>=r)
	{
		maintain(o,l,r,val);
		return;
	}
	down(o,l,r);
	if(y1<=mid) update(lc,l,mid,y1,y2,val);
	if(y2>mid) update(rc,mid+1,r,y1,y2,val);
	up(o);
}
void dfs2(int u,int pre)
{
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,1);
	ans[u]=max(0,sum[1]-1);
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs2(v,u);
	}
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,-1);
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		int u,v;
		for(int i=1;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			addedge(u,v);
			addedge(v,u);
		}
		tim=0;
		dfs1(1,-1);
		while(m--)
		{
			scanf("%d%d",&u,&v);
			op[u].push_back(P(in[v],out[v]));
			op[u].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[v],out[v]));
		}
		memset(mn,0,sizeof(mn));
		memset(ans,0,sizeof(ans));
		memset(addv,0,sizeof(addv));
		dfs2(1,-1);
		for(int i=1;i<=n;++i)
			printf("%d%c",ans[i],i==n?'\n':' ');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define P pair<int,int>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
struct Edge
{
	int to,next;
}edge[maxn<<1];
int head[maxn],tot;
void addedge(int u,int v)
{
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
vector<P>op[maxn];
int tim;
int in[maxn],out[maxn];
int n,m;
void dfs1(int u,int pre)
{
	in[u]=++tim;
	op[u].clear();
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs1(v,u);
	}
	out[u]=tim;
}
int ans[maxn];
int mn[maxn<<2],addv[maxn<<2],sum[maxn<<2];
void maintain(int o,int l,int r,int val)
{
	addv[o]+=val;
	mn[o]+=val;
	if(mn[o]>0) sum[o]=r-l+1;
	else if(l==r) sum[o]=0;
	else sum[o]=sum[lc]+sum[rc];
}
void down(int o,int l,int r)
{
	if(addv[o]!=0)
	{
		maintain(lc,l,mid,addv[o]);
		maintain(rc,mid+1,r,addv[o]);
		addv[o]=0;
	}
}
void up(int o)
{
	mn[o]=min(mn[lc],mn[rc]);
	sum[o]=sum[lc]+sum[rc];
}
void update(int o,int l,int r,int y1,int y2,int val)
{
	if(y1<=l&&y2>=r)
	{
		maintain(o,l,r,val);
		return;
	}
	down(o,l,r);
	if(y1<=mid) update(lc,l,mid,y1,y2,val);
	if(y2>mid) update(rc,mid+1,r,y1,y2,val);
	up(o);
}
void dfs2(int u,int pre)
{
	if(op[u].size()>0)
	{
		update(1,1,n,in[u],out[u],1);
		for(int i=0;i<op[u].size();++i)
			update(1,1,n,op[u][i].first,op[u][i].second,1);
	}
	ans[u]=max(0,sum[1]-1);
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs2(v,u);
	}
	if(op[u].size()>0)
	{
		update(1,1,n,in[u],out[u],-1);
		for(int i=0;i<op[u].size();++i)
			update(1,1,n,op[u][i].first,op[u][i].second,-1);
	}
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		int u,v;
		for(int i=1;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			addedge(u,v);
			addedge(v,u);
		}
		tim=0;
		dfs1(1,-1);
		while(m--)
		{
			scanf("%d%d",&u,&v);
			op[u].push_back(P(in[v],out[v]));
			op[v].push_back(P(in[u],out[u]));
		}
		memset(mn,0,sizeof(mn));
		memset(ans,0,sizeof(ans));
		memset(addv,0,sizeof(addv));
		dfs2(1,-1);
		for(int i=1;i<=n;++i)
			printf("%d%c",ans[i],i==n?'\n':' ');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define P pair<int,int>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
struct Edge
{
	int to,next;
}edge[maxn<<1];
int head[maxn],tot;
void addedge(int u,int v)
{
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
vector<P>op[maxn];
int tim;
int in[maxn],out[maxn];
int n,m;
void dfs1(int u,int pre)
{
	in[u]=++tim;
	op[u].clear();
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs1(v,u);
	}
	out[u]=tim;
}
int ans[maxn];
int mn[maxn<<2],addv[maxn<<2],sum[maxn<<2];
void maintain(int o,int l,int r,int val)
{
	addv[o]+=val;
	mn[o]+=val;
	if(mn[o]>0) sum[o]=r-l+1;
	else if(l==r) sum[o]=0;
	else sum[o]=sum[lc]+sum[rc];
}
void down(int o,int l,int r)
{
	if(addv[o]!=0)
	{
		maintain(lc,l,mid,addv[o]);
		maintain(rc,mid+1,r,addv[o]);
		addv[o]=0;
	}
}
void up(int o)
{
	mn[o]=max(mn[lc],mn[rc]);
	sum[o]=sum[lc]+sum[rc];
}
void update(int o,int l,int r,int y1,int y2,int val)
{
	if(y1<=l&&y2>=r)
	{
		maintain(o,l,r,val);
		return;
	}
	down(o,l,r);
	if(y1<=mid) update(lc,l,mid,y1,y2,val);
	if(y2>mid) update(rc,mid+1,r,y1,y2,val);
	up(o);
}
void dfs2(int u,int pre)
{
	if(op[u].size()>0)
	{
		update(1,1,n,in[u],out[u],1);
		for(int i=0;i<op[u].size();++i)
			update(1,1,n,op[u][i].first,op[u][i].second,1);
	}
	ans[u]=max(0,sum[1]-1);
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs2(v,u);
	}
	if(op[u].size()>0)
	{
		update(1,1,n,in[u],out[u],-1);
		for(int i=0;i<op[u].size();++i)
			update(1,1,n,op[u][i].first,op[u][i].second,-1);
	}
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		int u,v;
		for(int i=1;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			addedge(u,v);
			addedge(v,u);
		}
		tim=0;
		dfs1(1,-1);
		while(m--)
		{
			scanf("%d%d",&u,&v);
			op[u].push_back(P(in[v],out[v]));
			op[v].push_back(P(in[u],out[u]));
		}
		memset(mn,0,sizeof(mn));
		memset(ans,0,sizeof(ans));
		memset(addv,0,sizeof(addv));
		dfs2(1,-1);
		for(int i=1;i<=n;++i)
			printf("%d%c",ans[i],i==n?'\n':' ');
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define P pair<int,int>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
struct Edge
{
	int to,next;
}edge[maxn<<1];
int head[maxn],tot;
void addedge(int u,int v)
{
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void init()
{
	memset(head,-1,sizeof(head));
	tot=0;
}
vector<P>op[maxn];
int tim;
int in[maxn],out[maxn];
int n,m;
void dfs1(int u,int pre)
{
	in[u]=++tim;
	op[u].clear();
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs1(v,u);
	}
	out[u]=tim;
}
int ans[maxn];
int mn[maxn<<2],addv[maxn<<2],sum[maxn<<2];
void maintain(int o,int l,int r,int val)
{
	addv[o]+=val;
	mn[o]+=val;
	if(mn[o]>0) sum[o]=r-l+1;
	else if(l==r) sum[o]=0;
	else sum[o]=sum[lc]+sum[rc];
}
void down(int o,int l,int r)
{
	if(addv[o]!=0)
	{
		maintain(lc,l,mid,addv[o]);
		maintain(rc,mid+1,r,addv[o]);
		addv[o]=0;
	}
}
void up(int o)
{
	mn[o]=min(mn[lc],mn[rc]);
	sum[o]=sum[lc]+sum[rc];
}
void update(int o,int l,int r,int y1,int y2,int val)
{
	if(y1<=l&&y2>=r)
	{
		maintain(o,l,r,val);
		return;
	}
	//down(o,l,r);
	if(y1<=mid) update(lc,l,mid,y1,y2,val);
	if(y2>mid) update(rc,mid+1,r,y1,y2,val);
	maintain(o,l,r,0);
}
void dfs2(int u,int pre)
{
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,1);
	ans[u]=max(0,sum[1]-1);
	for(int i=head[u];~i;i=edge[i].next)
	{
		int v=edge[i].to;
		if(v==pre) continue;
		dfs2(v,u);
	}
	for(int i=0;i<op[u].size();++i)
		update(1,1,n,op[u][i].first,op[u][i].second,-1);
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		int u,v;
		for(int i=1;i<n;++i)
		{
			scanf("%d%d",&u,&v);
			addedge(u,v);
			addedge(v,u);
		}
		tim=0;
		dfs1(1,-1);
		while(m--)
		{
			scanf("%d%d",&u,&v);
			op[u].push_back(P(in[v],out[v]));
			op[u].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[u],out[u]));
			op[v].push_back(P(in[v],out[v]));
		}
		memset(mn,0,sizeof(mn));
		memset(ans,0,sizeof(ans));
		memset(addv,0,sizeof(addv));
		dfs2(1,-1);
		for(int i=1;i<=n;++i)
			printf("%d%c",ans[i],i==n?'\n':' ');
	}
	return 0;
}


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

int a[6000000];
int t[6000000];
int lazy[6000000];
int c[6000000];
int k[6000000];

int n,m,op;

int w[600006];
int dis[600006];
vector<int> q[600005];
vector<int> p[600005];

void down(int l,int r,int id)
{
    int mid=(l+r)/2;
    lazy[id*2]+=lazy[id];
    lazy[id*2+1]+=lazy[id];
    t[id*2]+=(mid-l+1)*lazy[id];
    t[id*2+1]+=(r-mid)*lazy[id];
    lazy[id]=0;
}

void update(int l,int r,int z,int y,int v,int id)
{
    if(l==z&&r==y)
    {
        t[id]+=(r-l+1)*v;
        c[id]+=v;
        lazy[id]+=v;
        if(c[id]>0)k[id]=(r-l+1);
        else k[id]=k[id*2]+k[id*2+1];
        return ;
    }
    down(l,r,id);
    int mid=(l+r)/2;
    if(mid>=y)update(l,mid,z,y,v,id*2);
    else if(mid<z)update(mid+1,r,z,y,v,id*2+1);
    else
    {
        update(l,mid,z,mid,v,id*2);
        update(mid+1,r,mid+1,y,v,id*2+1);
    }
    t[id]=t[id*2]+t[id*2+1];
    if(c[id]>0)k[id]=(r-l+1);
    else
        k[id]=k[id*2]+k[id*2+1];
}

int cck(int l,int r,int x,int id)
{
    if(l==r&&l==x)
    {
        if(t[id]>0)
            return 1;
        else return 0;
    }
    down(l,r,id);
    int mid=(l+r)/2;
    if(mid>=x)return cck(l,mid,x,id*2);
    else return cck(mid+1,r,x,id*2+1);
}

void dfs(int x,int last)
{
    op++;
    dis[x]=op;
    for(int i=0;i<q[x].size();i++)
    {
        int nx=q[x][i];
        if(nx==last)continue;
        dfs(nx,x);
        w[x]+=w[nx];
    }
    w[x]+=1;
}

int ans[600000];

void dd(int x,int last)
{
    for(int i=0;i<p[x].size();i++)
    {
        int nx=p[x][i];
        update(1,op,dis[x],dis[x]+w[x]-1,1,1);
        update(1,op,dis[nx],dis[nx]+w[nx]-1,1,1);
    }
    ans[x]=k[1]-cck(1,op,dis[x],1);
    for(int i=0;i<q[x].size();i++)
    {
        int nx=q[x][i];
        if(nx==last)continue;
        dd(nx,x);
    }
    for(int i=0;i<p[x].size();i++)
    {
        int nx=p[x][i];
        update(1,op,dis[x],dis[x]+w[x]-1,-1,1);
        update(1,op,dis[nx],dis[nx]+w[nx]-1,-1,1);
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        q[x].push_back(y);
        q[y].push_back(x);
    }
    dfs(1,1);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        p[x].push_back(y);
        p[y].push_back(x);
    }
    dd(1,1);
    for(int i=1;i<=n;i++)
    {
        printf("%d ",ans[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#define lson id<<1,l,m
#define rson id<<1|1,m+1,r
using namespace std;
typedef long long ll;
const int maxn=300000+100;
int x,y;
struct link_edge
{
    int v,next;
}edge[maxn];
int en;
int g[maxn];
int ct[maxn];
struct node
{
    int id,pre;
    int l,r;
    int data;
}tree[maxn];
vector<int>que[maxn];
int n,m,p,q;
int id;
int ans[maxn];
struct segmenttree
{
    int add[maxn<<2];
    int dt[maxn<<2];

    void init()
    {
        memset(dt,0,sizeof dt);
        memset(add,0,sizeof add);
    }
    void pushup(int id,int m)
    {
        if (add[id])
        {
            dt[id]=m;
            return;
        }
        else if (m==1) dt[id]=0;
        else dt[id]=dt[id<<1]+dt[id<<1|1];
    }
    void modify(int L,int R,int id,int l,int r,int c)
    {
        if (L==l && R==r)
        {
            add[id]+=c;
            pushup(id,r-l+1);
            return;
        }
        int m=(l+r)>>1;
        if (R<=m) modify(L,R,lson,c);
        else if (L>m) modify(L,R,rson,c);
        else {
            modify(L,m,lson,c); modify(m+1,R,rson,c);
        }
        pushup(id,r-l+1);
    }
}sgt;
void dfs(int i,int pre)
{
    tree[i].id=id;
    for (int j=g[i]; j!=-1; j=edge[j].next)
    {
        if (edge[j].v==pre) continue;

        id++;
        dfs(edge[j].v,i);
    }
}
void dfs_find(int i,int &minn,int &maxx,int pre)
{
    int k;
    minn=tree[i].id;
    maxx=tree[i].id;
    for (int j=g[i]; j!=-1; j=edge[j].next)
    {
        k=edge[j].v;
        if (k==pre) continue;
        dfs_find(k,tree[k].l,tree[k].r,i);
//        minn=min(minn,min(tree[k].l,tree[k].id));
        maxx=max(maxx,tree[k].r);
    }
    if (minn==999999999) minn=tree[i].id;
}
void work(int u,int pre)
{

    for (int i=0; i<que[u].size(); i++)
    {
        int v=que[u][i];
        sgt.modify(tree[v].l,tree[v].r,1,1,n,1);
    }
    ans[u]+=sgt.dt[1];
    if (ans[u]) ans[u]--;
    for (int j=g[u]; j!=-1; j=edge[j].next)
    {
        if (edge[j].v==pre) continue;
        work(edge[j].v,u);
    }
    for (int i=0; i<que[u].size(); i++)
    {
        int v=que[u][i];
        sgt.modify(tree[v].l,tree[v].r,1,1,n,-1);
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    memset(g,-1,sizeof g);
    memset(ans,0,sizeof ans);
    en=0;
    scanf("%d%d",&n,&m);
    for (int i=1; i<n; i++)
    {
        scanf("%d%d",&x,&y);
        edge[en].v=y;
        edge[en].next=g[x];
        g[x]=en;
        en++;

        edge[en].v=x;
        edge[en].next=g[y];
        g[y]=en;
        en++;

    }
    tree[1].id=1;
    id=1;
    dfs(1,-1);
    dfs_find(1,tree[1].l,tree[1].r,-1);
//    for (int i=1; i<=n; i++)
    sgt.init();
    for (int i=1; i<=m; i++)
    {
        scanf("%d%d",&x,&y);
        que[x].push_back(x);
        que[x].push_back(y);
        que[y].push_back(x);
        que[y].push_back(y);
    }
    work(1,-1);
    for(int i=1; i<=n; i++) cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=110000;
struct node
{
    int nxt,ed;
}e[3*N];
struct node1
{
    int l,r,f,lazy;
}T[4*N];
int head[N],num,dep,L[N],R[N],ans[N];
vector<int>v[N];
void add(int x,int y)
{
    e[num].nxt=head[x];
    e[num].ed=y;
    head[x]=num++;
}
void init()
{
    num=0;
    memset(head,-1,sizeof(head));
}
void dfs(int u,int fa)
{
    L[u]=++dep;
    for(int i=head[u];~i;i=e[i].nxt){
        int v=e[i].ed;
        if(v==fa) continue;
        dfs(v,u);
    }
    R[u]=dep;
}
void build(int id,int l,int r)
{
    T[id].l=l,T[id].r=r,T[id].f=0,T[id].lazy=0;
    if(l==r) return;
    int mid=(l+r)/2;
    build(2*id,l,mid);
    build(2*id+1,mid+1,r);
}
/*void pushdown(int id)
{
    if(T[id].lazy){
        T[2*id].lazy+=T[id].lazy,T[2*id+1].lazy+=T[id].lazy;
        T[2*id].f=T[2*id].r-T[2*id].l+1,T[2*id+1].f=T[2*id+1].r-T[2*id+1].l+1;
        T[id].lazy=0;
    }
    else{
        T[2*id].f=T[2*id].lazy=0;
        T[2*id+1].f=T[2*id+1].lazy=0;
    }
}*/
void update(int id,int l,int r,int k)
{
    if(T[id].l>=l&&T[id].r<=r){
        T[id].lazy+=k;
        if(T[id].lazy) T[id].f=T[id].r-T[id].l+1;
        else if(T[id].l==T[id].r) T[id].f=0;
        else T[id].f=T[2*id].f+T[2*id+1].f;
        return ;
    }
    //pushdown(id);
    int mid=(T[id].l+T[id].r)/2;
    if(l<=mid) update(2*id,l,r,k);
    if(r>mid) update(2*id+1,l,r,k);
    if(T[id].lazy) T[id].f=T[id].r-T[id].l+1;
    else{
        T[id].f=T[2*id].f+T[2*id+1].f;
    }
}
void solve(int u,int fa)
{
    for(int i=0;i<(int)v[u].size();i++){
        int t=v[u][i];
        update(1,L[t],R[t],1);
    }
    ans[u]=T[1].f;
    if(ans[u]) ans[u]--;
    for(int i=head[u];~i;i=e[i].nxt){
        int t=e[i].ed;
        if(t==fa) continue;
        solve(t,u);
    }
    for(int i=0;i<(int)v[u].size();i++){
        int t=v[u][i];
        update(1,L[t],R[t],-1);
    }
}
int main()
{
    int n,m,x,y;
    init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
    }
    dfs(1,-1);
    build(1,1,n);
    for(int i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        v[x].push_back(y),v[x].push_back(x);
        v[y].push_back(y),v[y].push_back(x);
    }
    solve(1,-1);
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int c[200000], v[200000], g[200001];
int n, k, s, t;

check(int x){
    if(x < g[k]) return 0;
    int ans = 0;
    for(int i = 0; i <= k; i++){
        ans += g[i] * 2 - min(g[i], x - g[i]);
        //cout << ans << endl;
    }
    if(ans > t) return 0; else return 1;
}

int main()
{

    cin >> n >> k >> s >> t;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
    }
    for(int i = 0; i < k; i++){
        cin >> g[i];
    }
    sort(g, g + k);
    g[k] = s - g[k - 1];
    for(int i = k - 1; i > 0; i--){
        g[i] = g[i] - g[i - 1];
    }
    sort(g, g + k + 1);
    //for(int i = 0; i <= k; i++){
        //cout << g[i] << " ";
    //}
    int l = 0, r = 1000000000;
    int mid = (l + r) / 2;
    for(; r != l; mid = (l + r) / 2){
        //cout << l << " " << r << " " << mid << endl;
        if(check(mid)) r = mid; else l = mid + 1;
    }
    //cout << l << endl;
    int ans = 1000000007;
    for(int i = 0; i < n; i++){
            if(v[i] >= l)
            ans = min(ans, c[i]);
    }
    if(ans == 1000000007) cout << -1; else cout << ans;
    //cout << endl << endl;
    //check(8);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int c[200000], v[200000], g[200001];
int n, k, s, t;

check(int x){
    int u = g[0];
    int ans = u * 2 - min(u, x - u);
    for(int i = 1; i <= k; i++){
        u = g[i] - g[i - 1];
        if(u > x) return 0;
        ans += u * 2 - min(u, x - u);
        //cout << ans << endl;
    }
    if(ans > t) return 0; else return 1;
}

int main()
{

    cin >> n >> k >> s >> t;
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
    }
    for(int i = 0; i < k; i++){
        cin >> g[i];
    }
    sort(g, g + k);
    g[k] = s;
    //for(int i = 0; i <= k; i++){
        //cout << g[i] << " ";
    //}
    int l = 0, r = 1000000000;
    int mid = (l + r) / 2;
    for(; r != l; mid = (l + r) / 2){
        //cout << l << " " << r << " " << mid << endl;
        if(check(mid)) r = mid; else l = mid + 1;
    }
    //cout << l << endl;
    int ans = 1000000007;
    for(int i = 0; i < n; i++){
            if(v[i] >= l)
            ans = min(ans, c[i]);
    }
    if(ans == 1000000007) cout << -1; else cout << ans;
    //cout << endl << endl;
    //check(8);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long c[200000], v[200000], g[200001];
long long n, k, s, t;

check(long long x){
    long long u = g[0];
    int ans = u * 2 - min(u, x - u);
    for(int i = 1; i <= k; i++){
        u = g[i] - g[i - 1];
        if(u > x) return 0;
        ans += u * 2 - min(u, x - u);
        //cout << ans << endl;
    }
    if(ans > t) return 0; else return 1;
}

int main()
{

    cin >> n >> k >> s >> t;
    if(t < s) {
        cout << -1;
        return 0;
    }
    for(int i = 0; i < n; i++){
        cin >> c[i] >> v[i];
    }
    for(int i = 0; i < k; i++){
        cin >> g[i];
    }
    sort(g, g + k);
    g[k] = s;
    //for(int i = 0; i <= k; i++){
        //cout << g[i] << " ";
    //}
    long long l = 0, r = 2000000000;
    long long mid = (l + r) / 2;
    for(; r > l; mid = (l + r) / 2){
        //cout << l << " " << r << " " << mid << endl;
        if(check(mid)) r = mid; else l = mid + 1;
    }
    //cout << l << endl;
    long long ans = 2000000007;
    for(int i = 0; i < n; i++){
            if(v[i]     >= l)
            ans = min(ans, c[i]);
    }
    if(ans == 2000000007) cout << -1; else cout << ans;
    //cout << endl << endl;
    //check(8);
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int l = 0, r = int(1e10), m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0;i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    ll l = 0, r = cars.size(), m;
    while (l < r) {
        m = l + (r-l) / 2;
        if (f(cars[m].first) != INF)
            r = m-1;
        else
            l = m;

    }

    int left_bound = (r == 0) ? r : r+1;
    int min_cost = INF;
    for (int i = left_bound; i < cars.size(); ++i) {
        if (f(cars[i].first) <= t) min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int l = 0, r = int(1e9), m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0;i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int l = 0, r = int(1e9), m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0;i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<int> stops(MAX_K, -1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < k+1) {
        int dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        int l = 0, r = dist;
        while (l < r) {
            int m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    int n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int min_cost = INF;
    for (pii car : v) {
        if (f(car.second) <= t) min_cost = min(min_cost, car.first);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += min(dist, v - dist);
        else return -1;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());
    ll i = distance(cars.begin(), lower_bound(cars.begin(), cars.end(), make_pair(max_len, -1)));
    int min_cost = INF;
    for (;i < cars.size(); ++i) {
        min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);
vector<ll> mem(MAX_V, -1);

ll f(int v) {
    if (mem[v] != -1) return mem[v];
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    mem[v] = res;
    return mem[v];
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> v(n);

    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    int min_cost = INF;
    for (pii car : v) {
        if (car.second >= max_len && f(car.second) <= t) min_cost = min(min_cost, car.first);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = int(1e9);

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    int l = 0, r = 1e9, m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0;i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    ll l = 0, r = cars.size(), m;
    while (l < r) {
        m = l + (r-l) / 2;
        if (f(cars[m].first) != INF)
            r = m-1;
        else
            l = m;

    }

    int left_bound = r+1;
    int min_cost = INF;
    for (int i = left_bound; i < cars.size(); ++i) {
        if (f(cars[i].first) <= t) min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 1;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    int left_bound = 0;
    ll l = 0, r = cars.size()-1, m;
    int iter = 0;
    while (iter < 1000) {
        m = l + (r-l) / 2;
        if (f(cars[m].first) != INF)
            r = m-1;
        else
            l = m;
    }

    left_bound = r;

    int min_cost = INF;
    for (int i = left_bound; i < cars.size(); ++i) {
        min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    ll l = 0, r = cars.size(), m;
    while (l < r) {
        m = l + (r-l) / 2;
        if (f(cars[m].first) < INF)
            r = m;
        else
            l = m+1;

    }

    int left_bound = r+1;
    int min_cost = INF;
    for (int i = left_bound; i < cars.size(); ++i) {
        if (f(cars[i].first) <= t) min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    int n, s, t;
    scanf("%d %d %d %d", &n, &k, &s, &t);

    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        scanf("%d%d", cars[i].second, cars[i].first);
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int l = 0, r = int(1e9) + 5, m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0; i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        printf("%d", min_cost);
    else printf("-1");
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<int> stops(MAX_K, -1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < k+1) {
        int dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        int l = 0, r = dist;
        while (l < r) {
            int m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    int n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());

    int min_cost = INF;
    for (pii car : v) {
        if (f(car.second) <= t) min_cost = min(min_cost, car.first);
    }

    cout << min_cost;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    int l = 0, r = cars.size(), m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        if (f(cars[m].second) <= t)
            r = m;
        else
            l = m;
        iter++;
    }
    int i = r;

    int min_cost = INF;
    for (;i < cars.size(); ++i) {
        min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    ll l = 0, r = cars.size()-1, m;
    while (r - l > 1) {
        m = l + (r-l) / 2;
        if (f(cars[m].first) != INF)
            r = m-1;
        else
            l = m;
    }

    int left_bound = (r == 0) ? r : r+1;
    int min_cost = INF;
    for (int i = left_bound; i < cars.size(); ++i) {
        if (f(cars[i].first) <= t) min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    sort(cars.begin(), cars.end());

    int l = 0, r = cars.size(), m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(cars[m].first);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }
    int i = (f(cars[l].first) <= t) ? l : r;

    int min_cost = INF;
    for (;i < cars.size(); ++i) {
        min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);

ll f(int v) {
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (v >= dist)
            res += 2 * dist - min(dist, v - dist);
        else return INF;
        i++;
    }
    return res;
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> cars(n);

    for (int i = 0; i < n; ++i) {
        cin >> cars[i].second >> cars[i].first;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    int l = 0, r = 1e9, m;
    int iter = 0;
    while (r - l > 1 && iter < 50) {
        m = l + (r-l) / 2;
        ll temp = f(m);
        if (temp <= t)
            r = m;
        else
            l = m;
        iter++;
    }

    int min_cost = INF;
    for (int i = 0;i < cars.size(); ++i) {
        if (cars[i].first >= r)
            min_cost = min(min_cost, cars[i].second);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}


const bool is_testing = 0;

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int INF = 0x7FFFFFFF;

bool compv(pii p1, pii p2) {
    return p1.second < p2.second;
}

const int MAX_K = int(2 * 1e5 + 2);
int k;
vector<ll> stops(MAX_K, -1);
const int MAX_V = int(1e9 + 1);
vector<unsigned int> mem(MAX_V, 0);

ll f(int v) {
    if (mem[v] != 0) return mem[v];
    int i = 0;

    int res = 0;
    while (i < stops.size()-1) {
        ll dist = stops[i+1] - stops[i];
        if (dist > v) return INF;

        ll l = 0, r = dist, m;
        while (l < r) {
            m = l + (r-l)/2;
            if (2 * m + (dist-m) < v)
                l = m+1;
            else
                r = m;
        }
        res += l + 2 * (dist - l);
        i++;
    }
    mem[v] = res;
    return mem[v];
}

int main() {
    if (is_testing)
        freopen("/home/birdi/cpp/in.txt", "r", stdin);
    ll n, s, t;
    cin >> n >> k >> s >> t;
    stops.resize(k+2);
    vector<pii> v(n);

    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }

    stops[0] = 0;
    for (int i = 1; i <= k; ++i) {
        cin >> stops[i];
    }
    stops[k+1] = s;

    sort(stops.begin(), stops.end());
    ll max_len = -1;
    for (int i = 0; i < stops.size()-1; ++i) {
        max_len = max(max_len, stops[i + 1] - stops[i]);
    }

    int min_cost = INF;
    for (pii car : v) {
        if (car.second >= max_len && f(car.second) <= t) min_cost = min(min_cost, car.first);
    }

    if (min_cost < INF)
        cout << min_cost;
    else cout << -1;
    return 0;
}