#include <bits/stdc++.h>
#define int long long
#define BIT(i, x) (((x) >> (i)) & 1)
#define task ""
using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5 + 2;
const ll Inf = 1e16;
int n, m, k;
int x[20];
int dp[N];
ll d[20][N];
vector<pair<int, ll>> nadj[N];
int bonker[20];

void Read()
{
    cin >> n >> k;
	m = n - 1;
    for (int i = 1; i <= m; ++i)
    {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        nadj[u].push_back({v, w});
        nadj[v].push_back({u, w});
    }
    for (int i = 1; i <= k; ++i)
        cin >> bonker[i] >> x[i];
}

bool Check(int v)
{
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= n; ++i)
    {
        int cur = 0;
        for (int j = 1; j <= k; ++j)
            if (d[j][i] <= v)
                cur |= 1 << (j - 1);
        ++dp[cur];
    }
    //cout << dp[1] << "\n";
    for (int i = 1; i <= k; ++i)
        for (int j = 1; j < (1 << k); ++j)
            if (BIT(i - 1, j))
                dp[j] += dp[j ^ (1 << (i - 1))];
    for (int j = 0; j < (1 << k); ++j)
    {
        ll cap = 0;
        for (int i = 0; i < k; ++i)
            if (BIT(i, j))
                cap += x[i + 1];
        //cout << j << ": " << cap << " " << dp[j] << "\n";
        if (cap < dp[j])
            return false;
    }
    return true;
}

bool Relax(int son, int par, ll w, ll d[N])
{
    if (d[son] > d[par] + w)
    {
        d[son] = d[par] + w;
        return true;
    }
    return false;
}

void Dijkstra(int x, ll d[N])
{
    fill_n(d, N, Inf);
    d[x] = 0;
    struct Tque
    {
        int v;
        ll w;
        Tque() {}
        Tque(int v, ll w)
        {
            this->v = v;
            this->w = w;
        }
        bool operator<(const Tque &a) const
        {
            return w > a.w;
        }
        bool Valid(ll d[])
        {
            return d[v] == w;
        }
    };
    priority_queue<Tque> s;
    s.push(Tque(x, 0));
    while (s.size())
    {
        Tque c = s.top();
        s.pop();
        if (!c.Valid(d))
            continue;
        for (auto i : nadj[c.v])
            if (Relax(i.first, c.v, i.second, d))
                s.push(Tque(i.first, d[i.first]));
    }
}

void Solve()
{

    for (int i = 1; i <= k; ++i)
        Dijkstra(bonker[i], d[i]);
    ll l = 0, m, h = Inf;
    while (l <= h)
    {
        m = (l + h) / 2;
        if (Check(m))
            h = m - 1;
        else
            l = m + 1;
    }
    cout << l;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen(task ".INP", "r"))
    {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    Read();
    Solve();
}