#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7, M = N * 30;
const long long inf = 1e15;
int n, m, ch[M][2], tot;
long long mn[M], tag[M];
void add(int &id, int L, int R, int pos, long long w) {
  if (!id) id = ++tot, mn[id] = inf, tag[id] = 0;
  mn[id] = min(mn[id], w);
  if (L == R) return;
  int mid = (L + R) >> 1;
  if (pos <= mid)
    add(ch[id][0], L, mid, pos, w);
  else
    add(ch[id][1], mid + 1, R, pos, w);
}
void ad(int first, long long second) {
  if (first)
    mn[first] += second, mn[first] = min(mn[first], inf), tag[first] += second,
                         tag[first] = min(tag[first], inf);
}
void pushdown(int first) {
  ad(ch[first][0], tag[first]), ad(ch[first][1], tag[first]), tag[first] = 0;
}
void cover(int id, int L, int R, int pos) {
  if (!id) return;
  if (L == R) return mn[id] = inf, void();
  int mid = (L + R) >> 1;
  pushdown(id);
  if (pos <= mid)
    cover(ch[id][0], L, mid, pos);
  else
    cover(ch[id][1], mid + 1, R, pos);
  mn[id] = min(mn[ch[id][0]], mn[ch[id][1]]);
}
int merge(int first, int second, int L, int R, long long xr, long long yr) {
  if (!first || !second) {
    if (!first && !second) return 0;
    if (!first) return ad(second, xr), second;
    if (!second) return ad(first, yr), first;
  }
  if (L == R)
    return mn[first] = min(min(mn[first] + yr, mn[second] + xr),
                           min(mn[first] + mn[second], inf)),
           first;
  pushdown(first), pushdown(second);
  int mid = (L + R) >> 1;
  ch[first][0] = merge(ch[first][0], ch[second][0], L, mid,
                       min(xr, mn[ch[first][1]]), min(yr, mn[ch[second][1]]));
  ch[first][1] = merge(ch[first][1], ch[second][1], mid + 1, R, xr, yr);
  mn[first] = min(mn[ch[first][0]], mn[ch[first][1]]);
  return first;
}
int ehd[N], dep[N], enx[N << 1], ev[N << 1], eid, hd[N];
void eadd(int u, int v) { ++eid, enx[eid] = ehd[u], ev[eid] = v, ehd[u] = eid; }
void dfs(int first, int fa) {
  for (int i = ehd[first]; i; i = enx[i])
    if (ev[i] != fa) dep[ev[i]] = dep[first] + 1, dfs(ev[i], first);
}
void Dfs(int first, int fa) {
  if (enx[ehd[first]] || first == 1) {
    int cnt = 0, v = 0;
    for (int i = ehd[first]; i; i = enx[i])
      if (ev[i] != fa) cnt++, v = ev[i];
    if (cnt == 1)
      Dfs(v, first), hd[first] = merge(hd[first], hd[v], 1, n, 0ll, inf);
    else {
      add(hd[first], 1, n, dep[first], 0);
      for (int i = ehd[first]; i; i = enx[i])
        if (ev[i] != fa)
          Dfs(ev[i], first),
              hd[first] = merge(hd[first], hd[ev[i]], 1, n, inf, inf);
    }
  }
  if (first > 1) cover(hd[first], 1, n, dep[first]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m, mn[0] = inf;
  for (int i = 1, iE = n - 1; i <= iE; i++) {
    int u, v;
    cin >> u >> v;
    eadd(u, v), eadd(v, u);
  }
  dep[1] = 1, dfs(1, 0);
  for (int i = 1, iE = m; i <= iE; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add(hd[u], 1, n, dep[v], w);
  }
  Dfs(1, 0);
  if (mn[hd[1]] >= inf)
    cout << "-1\n";
  else
    cout << mn[hd[1]] << "\n";
  return 0;
}
