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;
long long n, m, timer, size[630000];
long long rec[630000], dfn[630000];
long long mn[630000 << 1], mark[630000 << 1], f[630000];
long long read() {
  long long x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * k;
}
struct edge {
  long long cnp, to[630000], last[630000], head[630000];
  long long co[630000];
  edge() { cnp = 2; }
  void add(long long u, long long v, long long w = 0) {
    to[cnp] = v, co[cnp] = w, last[cnp] = head[u], head[u] = cnp++;
  }
} E1, G1, G2;
void Push_Down(long long p) {
  mark[p << 1] += mark[p], mark[p << 1 | 1] += mark[p];
  mn[p << 1] += mark[p], mn[p << 1 | 1] += mark[p];
  mark[p] = 0;
}
void Build(long long p, long long l, long long r) {
  if (l == r) {
    mn[p] = 0x3fffffffffffffff;
    return;
  }
  long long mid = (l + r) >> 1;
  Build(p << 1, l, mid), Build(p << 1 | 1, mid + 1, r);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
void Update(long long p, long long l, long long r, long long L, long long R,
            long long x) {
  if (L <= l && R >= r) {
    mark[p] += x;
    mn[p] += x;
    return;
  }
  if (L > r || R < l) return;
  long long mid = (l + r) >> 1;
  Push_Down(p);
  Update(p << 1, l, mid, L, R, x), Update(p << 1 | 1, mid + 1, r, L, R, x);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
void Modify(long long p, long long l, long long r, long long x, long long y) {
  if (l == r) {
    mn[p] = y;
    return;
  }
  long long mid = (l + r) >> 1;
  Push_Down(p);
  if (x <= mid)
    Modify(p << 1, l, mid, x, y);
  else
    Modify(p << 1 | 1, mid + 1, r, x, y);
  mn[p] = min(mn[p << 1], mn[p << 1 | 1]);
}
long long Query(long long p, long long l, long long r, long long L,
                long long R) {
  if (L <= l && R >= r) return mn[p];
  if (L > r || R < l) return 0x3fffffffffffffff;
  long long mid = (l + r) >> 1;
  return min(Query(p << 1, l, mid, L, R), Query(p << 1 | 1, mid + 1, r, L, R));
}
void pre(long long u, long long fa) {
  rec[u] = 1000000000;
  for (long long i = E1.head[u]; i; i = E1.last[i]) {
    long long v = E1.to[i];
    if (v == fa) continue;
    pre(v, u);
    size[u] += size[v];
    rec[u] = min(rec[u], rec[v]);
  }
  for (long long i = G1.head[u]; i; i = G1.last[i])
    dfn[G1.to[i]] = ++timer, rec[u] = min(rec[u], timer), size[u]++;
}
void dfs(long long u, long long fa) {
  long long sum = 0, flag = 0;
  for (long long i = E1.head[u]; i; i = E1.last[i]) {
    long long v = E1.to[i];
    if (v == fa) continue;
    dfs(v, u);
    sum += f[v];
  }
  if (u == 1) {
    f[1] = sum;
    return;
  }
  for (long long i = G1.head[u]; i; i = G1.last[i])
    Modify(1, 1, m, dfn[G1.to[i]], sum + G1.co[i]);
  for (long long i = G2.head[u]; i; i = G2.last[i])
    Modify(1, 1, m, dfn[G2.to[i]], 0x3fffffffffffffff);
  for (long long i = E1.head[u]; i; i = E1.last[i]) {
    long long v = E1.to[i];
    if (v == fa) continue;
    if (rec[v] < 1000000000)
      Update(1, 1, m, rec[v], rec[v] + size[v] - 1, sum - f[v]);
  }
  f[u] = rec[u] < 1000000000 ? Query(1, 1, m, rec[u], rec[u] + size[u] - 1)
                             : 0x3fffffffffffffff;
  if (f[u] >= 0x3fffffffffffffff) {
    printf("-1");
    exit(0);
  }
}
signed main() {
  n = read(), m = read();
  Build(1, 1, n);
  for (long long i = 1; i < n; i++) {
    long long u = read(), v = read();
    E1.add(u, v), E1.add(v, u);
  }
  for (long long i = 1; i <= m; i++) {
    long long u = read(), v = read(), w = read();
    G1.add(u, i, w), G2.add(v, i, w);
  }
  pre(1, 0);
  dfs(1, 0);
  if (f[1] < 0x3fffffffffffffff)
    printf("%I64d\n", f[1]);
  else
    printf("-1\n");
  return 0;
}