	#include<bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define pb push_back
	
	int n,k,u,v;
	vector<int> adj[200002];
	vector<int> leaf;
	int cnt = 0;
	bool vis[200002];
	int dfs(int u , int t){
		vis[u] = true;
		int cur = 0;
		int rec = 0;
		for(int i=0;i<adj[u].size();i++){
			if(!vis[adj[u][i]]){
				int temp = dfs(adj[u][i],t);
				cur = max(cur,1+temp);
				rec = min(rec,1+temp);
			}
		}
		rec = - rec;
		if(cur < rec){
			cur = -rec;
		}
		
		if(cur == t){
			cur = -t-1;
			++cnt;
		}
	//	cout<<u<<" "<<cur<<"\n";
		return cur;
	}
	bool poss(int t){
		//cout<<t<<"\n";
		for(int i=0;i<n;i++)
			vis[i] = false;
		cnt = 0;
		int c = dfs(0,t);
		 if(c>=0){
		 	++cnt;
		 }
		 if(cnt<=k)
		 	return true;
		 else
		 	return false;
	}
	int main()
	{
		cin>>n>>k;
		for(int i=0;i<n-1;i++){
			cin>>u>>v;
			--u,--v;
			adj[u].pb(v);
			adj[v].pb(u);
		}
		if(k>=n){
			cout<<0;
			return 0;
		}
		int l = 1;
		int r = (n/2) + 1;
		int ans = -1;
		while(l<=r){
			int mid = (l+r)/2;
			if(poss(mid)){
				ans = mid;
				r = mid-1;
			}else{
				l = mid+1;
			}	
		}
		cout<<ans;
		return 0;
	}
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int vi[200001];

vector<int> g[200001];

ll A[200001], b[200001];

ll ans=-1000000001;

ll maxi[200001];

void predfs(int u)
{
    vi[u]=1;

    for(int j=0;j<g[u].size();j++)
    {
        int v=g[u][j];
        if(!vi[v])
        {
            predfs(v);
        }
        maxi[u]=max(maxi[u], maxi[v]);
        maxi[u]=max(maxi[u], A[v]);
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    memset(vi, 0, sizeof vi);

    for(int i=1;i<=N;i++)
    {
        cin >> A[i];
        maxi[i]=-1000000001;
    }

    int X, Y;

    for(int i=0;i<M;i++)
    {
        cin >> X >> Y;
        g[X].push_back(Y);
    }

    for(int i=1;i<=N;i++)
    {
        if(!vi[i])
        {
            predfs(i);
        }
    }

    for(int i=1;i<=N;i++)
    {
        vi[i]=0;
        ans=max(ans, maxi[i]-A[i]);
    }
    cout << ans;
}
