#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 6e5+10;
const ll inf = 0x7f7f7f7f;
inline int read(){
int ref=0,x=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')x=-1;ch=getchar();}
while(isdigit(ch)){ref=ref*10+ch-'0';ch=getchar();}
return ref*x;
}
int n,m;
struct edge{
int next,to,w;
}a[N];
int cnt,head[N];
int fa[N][23],ljw[N][23],dis[N],dep[N];
int d[N],sum[N],vis[N],f[N];
int u[N],v[N],val[N],fro[N];
int ans=inf,l,r,limit;
void add(int u,int v,int w){
a[++cnt].w=w;
a[cnt].to=v;
a[cnt].next=head[u];
head[u]=cnt;
}
void dfs(int x,int deep){
dep[x]=deep;
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(dep[v]) continue;
fa[v][0]=x;
fro[v]=a[i].w;
dis[v]=dis[x]+a[i].w;
dfs(v,deep+1);
}
}
int lca(int x,int y){
if(dep[x]<dep[y]) swap(x,y);
for(int i=21;i>=0;i--){
if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
}
if(x==y) return x;
for(int i=21;i>=0;i--){
if(fa[x][i]!=fa[y][i]){
x=fa[x][i];
y=fa[y][i];
}
}
return fa[x][0];
}
void DFS1(int x){
sum[x]+=d[x];
for(int i=head[x];i;i=a[i].next){
int v=a[i].to;
if(vis[v]) continue;
vis[v]=1;
DFS1(v);
sum[x]+=sum[v];
}
}
bool check(int x){
int ljw=0,maxn=0;
memset(sum,0,sizeof(sum));
memset(vis,0,sizeof(vis));
memset(d,0,sizeof(d));
for(int i=1;i<=m;i++){
if(val[i]>x){
ljw++;
d[u[i]]++;
d[v[i]]++;
d[f[i]]-=2;
maxn=max(maxn,val[i]);
}
}
if(!ljw) return true;
DFS1(1);
for(int i=1;i<=n;i++){
if(sum[i]==ljw&&maxn-fro[i]<=x) return true;
}
return false;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<n;i++){
int x,y,z;
x=read(),y=read(),z=read();
add(x,y,z);
add(y,x,z);
}
dfs(1,1);
for(int j=1;j<=21;j++)
for(int i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1];
limit=r;
for(int i=1;i<=m;i++){
int x,y;
x=read(),y=read();
u[i]=x,v[i]=y;
f[i]=lca(x,y);
val[i]=dis[x]+dis[y]-2*dis[f[i]];
r=max(r,val[i]);
}
while(l<=r){
ll mid=(l+r)>>1;
if(check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%d",ans);
return 0;
}