#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 17;
const long long INF = LLONG_MAX >> 1;
vector<int> Adj[MAXN], A[MAXN], B[MAXN];
int n, m, st[MAXN], en[MAXN], id[MAXN], cost[MAXN], dt;
long long val[MAXN << 2], tag[MAXN << 2], res[MAXN];
void DFS(int u, int p) {
  st[u] = dt + 1;
  for (int i : A[u]) id[i] = ++dt;
  for (int v : Adj[u])
    if (v != p) DFS(v, u);
  en[u] = dt;
}
void Build(int rt, int l, int r) {
  val[rt] = INF;
  if (l != r) {
    int m = (l + r) >> 1;
    Build((rt << 1), l, m);
    Build((rt << 1 | 1), m + 1, r);
  }
}
void Update(int p, long long v, int rt, int l, int r) {
  if (l == r) {
    val[rt] = v;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    Update(p, v, (rt << 1), l, m);
  else
    Update(p, v, (rt << 1 | 1), m + 1, r);
  val[rt] = min(INF, min(val[(rt << 1)], val[(rt << 1 | 1)]) + tag[rt]);
}
void Add(int al, int ar, long long v, int rt, int l, int r) {
  if (al > ar) return;
  if (al == l && ar == r) {
    val[rt] = min(val[rt] + v, INF);
    tag[rt] = min(tag[rt] + v, INF);
    return;
  }
  int m = (l + r) >> 1;
  if (ar <= m)
    Add(al, ar, v, (rt << 1), l, m);
  else if (al > m)
    Add(al, ar, v, (rt << 1 | 1), m + 1, r);
  else
    Add(al, m, v, (rt << 1), l, m), Add(m + 1, ar, v, (rt << 1 | 1), m + 1, r);
  val[rt] = min(INF, min(val[(rt << 1)], val[(rt << 1 | 1)]) + tag[rt]);
}
long long Query(int al, int ar, int rt, int l, int r) {
  if (al > ar) return INF;
  if (al == l && ar == r) return val[rt];
  int m = (l + r) >> 1;
  if (ar <= m)
    return min(INF, Query(al, ar, (rt << 1), l, m) + tag[rt]);
  else if (al > m)
    return min(INF, Query(al, ar, (rt << 1 | 1), m + 1, r) + tag[rt]);
  else
    return min(INF, min(Query(al, m, (rt << 1), l, m),
                        Query(m + 1, ar, (rt << 1 | 1), m + 1, r)) +
                        tag[rt]);
}
void Solve(int u, int p) {
  long long ans = 0;
  for (int v : Adj[u])
    if (v != p) {
      Solve(v, u);
      ans = min(ans + res[v], INF);
    }
  if (u == 1) {
    res[1] = ans;
    return;
  }
  for (int i : A[u]) Update(id[i], ans + cost[i], 1, 1, m);
  for (int i : B[u]) Update(id[i], INF, 1, 1, m);
  for (int v : Adj[u])
    if (v != p) Add(st[v], en[v], ans - res[v], 1, 1, m);
  res[u] = Query(st[u], en[u], 1, 1, m);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    Adj[u].push_back(v);
    Adj[v].push_back(u);
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d%d", &l, &r, cost + i);
    A[l].push_back(i);
    B[r].push_back(i);
  }
  DFS(1, 0);
  Build(1, 1, m);
  Solve(1, 0);
  cout << (res[1] == INF ? -1 : res[1]) << "\n";
}
