#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
const int MAXN=500000;
const int INF=0x3f3f3f3f;
const int Mod=998244353;
#define mp make_pair
int n,m;
vector<pair<int,int> > G[MAXN+5];
int a[MAXN+5],b[MAXN+5],c[MAXN+5],ans[MAXN+5];
void DFS(int u,int fa){
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i].first,id=G[u][i].second;
		if(ans[id]||v==fa) continue;
		if(a[id]==u) ans[id]=1;
		else ans[id]=2;
		DFS(v,u);
	}
	return ;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		a[i]=read(),b[i]=read();
		G[a[i]].push_back(mp(b[i],i));	
		G[b[i]].push_back(mp(a[i],i));	
	}
	for(int i=1;i<=n;i++)
		c[i]=read();
	for(int i=1;i<=m;i++){
		if(c[a[i]]>c[b[i]]) 
			ans[i]=1;
		else if(c[a[i]]<c[b[i]])
			ans[i]=2;
	} 
	for(int i=1;i<=n;i++)
		DFS(i,-1);
	for(int i=1;i<=m;i++)
		puts(ans[i]==1?"->":"<-");
    return 0;
}
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int l = 0, r = n - 1;
    while (l < r) {
        int m = (l + r) / 2;
        int count = 0;
        std::function<int(int, int)> dfs = [&](int u, int p) {
            int x = 0;
            for (auto v : e[u]) {
                if (v == p) {
                    continue;
                }
                int y = dfs(v, u) + 1;
                if (x + y < 0) {
                    x = std::min(x, y);
                } else {
                    x = std::max(x, y);
                }
            }
            if (x == m) {
                x = -m - 1;
                count++;
            }
            return x;
        };
        if (dfs(0, -1) >= 0) {
            count++;
        }
        if (count <= k) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    std::cout << l << "\n";
    return 0;
}