#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}
const int N = 300009;
const long long Inf = 1e15 + 7;
int n, m;
int to[N << 1], nxt[N << 1], beg[N], val[N], tot;
int ord[N], id[N], ed[N], seg[N], fa[N], dfn;
long long f[N];
vector<int> in[N], out[N];
inline long long minn(long long a, long long b) {
  if (a < b) return a;
  return b;
}
namespace segt {
long long t[N << 2], tag[N << 2];
inline void mark(int x, long long v) {
  t[x] = minn(t[x] + v, Inf);
  tag[x] = minn(tag[x] + v, Inf);
}
inline void update(int x) { t[x] = minn(t[x << 1], t[x << 1 | 1]); }
inline void push(int x) {
  if (tag[x]) {
    mark(x << 1, tag[x]);
    mark(x << 1 | 1, tag[x]);
    tag[x] = 0;
  }
}
inline void build(int x, int l, int r) {
  if (l == r) {
    t[x] = Inf;
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  update(x);
}
inline void modify(int x, int l, int r, int p, long long v) {
  if (l == r) {
    t[x] = v;
    return;
  }
  push(x);
  int mid = l + r >> 1;
  if (p <= mid)
    modify(x << 1, l, mid, p, v);
  else
    modify(x << 1 | 1, mid + 1, r, p, v);
  update(x);
}
inline void add(int x, int l, int r, int dl, int dr, long long v) {
  if (dl == l && r == dr) {
    mark(x, v);
    return;
  }
  push(x);
  int mid = l + r >> 1;
  if (dr <= mid)
    add(x << 1, l, mid, dl, dr, v);
  else if (mid < dl)
    add(x << 1 | 1, mid + 1, r, dl, dr, v);
  else
    add(x << 1, l, mid, dl, mid, v),
        add(x << 1 | 1, mid + 1, r, mid + 1, dr, v);
  update(x);
}
inline long long query(int x, int l, int r, int dl, int dr) {
  if (dl == l && r == dr) return t[x];
  push(x);
  int mid = l + r >> 1;
  if (dr <= mid) return query(x << 1, l, mid, dl, dr);
  if (mid < dl) return query(x << 1 | 1, mid + 1, r, dl, dr);
  return minn(query(x << 1, l, mid, dl, mid),
              query(x << 1 | 1, mid + 1, r, mid + 1, dr));
}
}  // namespace segt
inline void add(int u, int v) {
  to[++tot] = v;
  nxt[tot] = beg[u];
  beg[u] = tot;
}
inline void dfs(int u) {
  id[u] = dfn + 1;
  for (int i = 0, e = in[u].size(); i < e; i++) ord[in[u][i]] = ++dfn;
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u]) {
      fa[to[i]] = u;
      dfs(to[i]);
    }
  ed[u] = dfn;
}
inline void dfs2(int u) {
  long long ans = 0;
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u]) {
      dfs2(to[i]);
      ans = minn(ans + f[to[i]], Inf);
    }
  if (u == 1) {
    f[1] = ans;
    return;
  }
  for (int i = 0, e = in[u].size(); i < e; i++)
    segt::modify(1, 1, m, ord[in[u][i]], ans + val[in[u][i]]);
  for (int i = 0, e = out[u].size(); i < e; i++)
    segt::modify(1, 1, m, ord[out[u][i]], Inf);
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u] && id[to[i]] <= ed[to[i]])
      segt::add(1, 1, m, id[to[i]], ed[to[i]], ans - f[to[i]]);
  if (id[u] <= ed[u])
    f[u] = segt::query(1, 1, m, id[u], ed[u]);
  else
    f[u] = Inf;
}
int main() {
  if (fopen("vj.in", "r")) {
    freopen("vj.in", "r", stdin);
    freopen("vj.out", "w", stdout);
  }
  n = read();
  m = read();
  for (int i = 1, u, v; i < n; i++) {
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    val[i] = read();
    in[u].push_back(i);
    out[v].push_back(i);
  }
  dfs(1);
  segt::build(1, 1, m);
  dfs2(1);
  printf("%I64d\n", (f[1] == Inf) ? -1 : f[1]);
  return 0;
}
