hj
#include<stdio.h>
#include<algorithm>
using namespace std;
#define Maxm 300009
#define Maxn 300009
#define inf (1<<29)
#define rep(i,j,k,l) for(int i=(j);(k);i+=(l))
int n,m,e,next[Maxn],begin[Maxn],to[Maxn],len[Maxn],msion[Maxm][4],dis[Maxm],r,dep[Maxn];
int ancestor[Maxn],;
void add(int a,int b,int c)
e++;
to[e]=b;
len[e]=a;
next[e]=begin[a];
begin[a]=e;
}
void dfs(int a,int b,int de,int ds){
dep[a]=de;
dis[a]=ds;
for(int i=begin[a];;i=next[i]){
int v=to[i];
if(v!=a){
ancestor[v]=a;
dfs(v,a,de+1,ds+len[i]);
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("P15D2T3.in","r",stdin);
freopen("P15D2T3.out","w",stdout);
#endif
r=inf;
scanf("%d %d",&n,&m);
rep(i,1,i<n,1){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dfs(1,1,0,0);dfs1();
rep(i,1,i<=m,1){
scanf("%d %d",&msion[i][0],&msion[i][1]);
msion[i][2]=LCA(msion[i][0],msion[i][1]);
msion[i][3]=dis[msion[i][0]]+dis[msion[i][1]]-(1<<dis[msion[i][2]]);
r=max(r,msion[i][3]);
}
++r;
int l=0,mid,ans=0;
while(l<r){
mid=(l+r)>>1;
if(check(mid)) ans=r=mid;
else l=mid+1;
}
printf("%d\n",ans);
}