Problem: Mayor of Yusland just won the lottery and decided to spent money on something good for town. For example, repair all the roads in the town.

Yusland consists of n intersections connected by n - 1 bidirectional roads. One can travel from any intersection to any other intersection using only these roads.

There is only one road repairing company in town, named "RC company". Company's center is located at the intersection 1. RC company doesn't repair roads you tell them. Instead, they have workers at some intersections, who can repair only some specific paths. The i-th worker can be paid ci coins and then he repairs all roads on a path from ui to some vi that lies on the path from ui to intersection 1. 

Mayor asks you to choose the cheapest way to hire some subset of workers in order to repair all the roads in Yusland. It's allowed that some roads will be repaired more than once.

If it's impossible to repair all roads print  - 1.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300 000) — the number of cities in Yusland and the number of workers respectively.

Then follow n−1 line, each of them contains two integers xi and yi (1 ≤ xi, yi ≤ n) — indices of intersections connected by the i-th road.

Last m lines provide the description of workers, each line containing three integers ui, vi and ci (1 ≤ ui, vi ≤ n, 1 ≤ ci ≤ 109). This means that the i-th worker can repair all roads on the path from vi to ui for ci coins. It's guaranteed that vi lies on the path from ui to 1. Note that vi and ui may coincide.

Output

If it's impossible to repair all roads then print  - 1. Otherwise print a single integer — minimum cost required to repair all roads using "RC company" workers.

Example

Input

6 5
1 2
1 3
3 4
4 5
4 6
2 1 2
3 1 4
4 1 3
5 3 1
6 3 2


Output

8

Note

In the first sample, we should choose workers with indices 1, 3, 4 and 5, some roads will be repaired more than once but it is OK. The cost will be equal to 2 + 3 + 1 + 2 = 8 coins.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int data = 0, m = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') {
    m = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = (data << 1) + (data << 3) + (ch ^ 48);
    ch = getchar();
  }
  return (m) ? data : -data;
}
namespace SegMent_Tree {
int n, m, fa[300005], dfn[300005], ed[300005], pos[300005], nS, Cost[300005],
    seq[300005], sz[300005];
long long tag[300005 << 2], mn[300005 << 2], f[300005];
vector<int> edge[300005], Ins[300005], Del[300005];
void PushDown(int o) {
  if (tag[o] == 0) return;
  mn[o << 1] += tag[o];
  mn[o << 1 | 1] += tag[o];
  tag[o << 1] += tag[o];
  tag[o << 1 | 1] += tag[o];
  tag[o] = 0;
}
void Build(int o, int l, int r) {
  if (l == r) mn[o] = 1e18;
  return;
  int mid = (l + r) >> 1;
  Build(o << 1, l, mid);
  Build(o << 1 | 1, mid + 1, r);
  mn[o] = 1e18;
}
void Add(int o, int l, int r, int ql, int qr, long long v) {
  if (ql <= l && r <= qr) return (void)(tag[o] += v, mn[o] += v);
  int mid = (l + r) >> 1;
  PushDown(o);
  if (ql <= mid) Add(o << 1, l, mid, ql, qr, v);
  if (qr > mid) Add(o << 1 | 1, mid + 1, r, ql, qr, v);
  mn[o] = min(mn[o << 1], mn[o << 1 | 1]);
}
void Insert(int o, int l, int r, int ps, long long v) {
  if (l == r) return (void)(mn[o] = v);
  int mid = (l + r) >> 1;
  PushDown(o);
  (ps <= mid) ? Insert(o << 1, l, mid, ps, v)
              : Insert(o << 1 | 1, mid + 1, r, ps, v);
  mn[o] = min(mn[o << 1], mn[o << 1 | 1]);
}
long long Query(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return mn[o];
  int mid = (l + r) >> 1;
  long long ret = 1e18;
  PushDown(o);
  if (ql <= mid) ret = min(ret, Query(o << 1, l, mid, ql, qr));
  if (qr > mid) ret = min(ret, Query(o << 1 | 1, mid + 1, r, ql, qr));
  return ret;
}
void dfs1(int u, int From) {
  fa[u] = From;
  dfn[u] = nS + 1;
  for (int j = 0, lt = Ins[u].size(); j < lt; ++j)
    seq[++nS] = Ins[u][j], pos[Ins[u][j]] = nS;
  sz[u] = Ins[u].size();
  for (auto v : edge[u])
    if (v ^ From) dfs1(v, u), sz[u] += sz[v];
  ed[u] = nS;
  if (!sz[u]) puts("-1"), exit(0);
}
void dfs2(int u, int From) {
  long long sum = 0;
  for (auto v : edge[u])
    if (v ^ From) dfs2(v, u), sum += f[v];
  if (sum >= 1e18) puts("-1"), exit(0);
  for (int j = 0, lt = Ins[u].size(), id; j < lt; j++)
    Insert(1, 1, nS, pos[Ins[u][j]], sum + Cost[Ins[u][j]]);
  for (auto v : edge[u])
    if ((v ^ From) && sz[v]) Add(1, 1, nS, dfn[v], ed[v], sum - f[v]);
  for (int j = 0, lt = Del[u].size(), id; j < lt; j++)
    Insert(1, 1, nS, pos[Del[u][j]], 1e18);
  f[u] = Query(1, 1, nS, dfn[u], ed[u]);
  return;
}
void main() {
  n = gi();
  m = gi();
  if (n == 1) puts("0"), exit(0);
  for (int i = 1, u, v; i < n; ++i)
    u = gi(), v = gi(), edge[u].push_back(v), edge[v].push_back(u);
  for (int i = 1, u, v, c; i <= m; ++i) {
    u = gi();
    v = gi();
    Cost[i] = gi();
    Ins[u].push_back(i);
    if (v != 1) Del[v].push_back(i);
  }
  dfs1(1, 0);
  Build(1, 1, nS);
  dfs2(1, 0);
  if (f[1] >= 1e18) puts("-1"), exit(0);
  cout << f[1] << endl;
}
}  // namespace SegMent_Tree
namespace Duality_Heap {
long long tag[300005], val[300005], Ans;
int tb[300005], lson[300005], rson[300005], rt[300005], up[300005],
    High[300005];
bool cov[300005];
vector<int> edge[300005];
int n, m;
inline void Add(int u, long long v) {
  tag[u] += v;
  val[u] += v;
}
inline void PushDown(int u) {
  if (tag[u] == 0) return;
  if (lson[u]) Add(lson[u], tag[u]);
  if (rson[u]) Add(rson[u], tag[u]);
  tag[u] = 0;
}
int Merge(int x, int y) {
  if (!x || !y) return x + y;
  PushDown(x);
  PushDown(y);
  if (val[x] > val[y]) swap(x, y);
  rson[x] = Merge(rson[x], y);
  if (High[lson[x]] < High[rson[x]]) swap(lson[x], rson[x]);
  High[x] = High[rson[x]] + 1;
  return x;
}
int Top(int &u) {
  while (cov[up[u]] && u) PushDown(u), u = Merge(lson[u], rson[u]);
  return val[u];
}
void dfs(int u, int From) {
  for (auto v : edge[u])
    if (v ^ From) dfs(v, u), rt[u] = Merge(rt[u], rt[v]), tb[u] += tb[v];
  cov[u] = true;
  int t = Top(rt[u]);
  Ans += t;
  if (t) Add(rt[u], -t);
  if (u != 1 && !tb[u]) puts("-1"), exit(0);
  return;
}
void main() {
  n = gi();
  m = gi();
  if (n == 1) puts("0"), exit(0);
  for (int i = 1, u, v; i < n; ++i)
    u = gi(), v = gi(), edge[u].push_back(v), edge[v].push_back(u);
  for (int i = 1, u, v, c; i <= m; i++) {
    u = gi();
    up[i] = gi();
    val[i] = gi();
    rt[u] = Merge(rt[u], i);
    tb[u]++;
    tb[up[i]]--;
  }
  Ans = 0;
  dfs(1, 0);
  cout << Ans << endl;
}
}  // namespace Duality_Heap
int main() {
  srand(time(NULL));
  int op = rand() % 1989;
  if (op & 1)
    SegMent_Tree::main();
  else
    Duality_Heap::main();
  return 0;
}