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;
const long long int inf = 1e15 + 5;
char ww;
inline void GET(int &t) {
  t = 0;
  do ww = getchar();
  while (ww < '0' || ww > '9');
  do t = t * 10 + ww - '0', ww = getchar();
  while (ww >= '0' && ww <= '9');
}
struct node {
  int v, next;
} edge[300005 << 2];
int adj[300005], w[300005], h[300005], in[300005], out[300005], pos, tot, n, m;
inline void add(int u, int v, int adj[]) {
  edge[++tot].v = v, edge[tot].next = adj[u], adj[u] = tot;
}
int st[300005], en[300005];
void dfs(int u, int fa) {
  st[u] = pos + 1;
  int p, v;
  for (p = in[u]; p; p = edge[p].next) h[edge[p].v] = ++pos;
  for (p = adj[u]; p; p = edge[p].next)
    if ((v = edge[p].v) != fa) dfs(v, u);
  en[u] = pos;
}
long long int dp[300005], sum[300005 << 2], tmp[300005 << 2];
inline void up(int p) {
  sum[p] = min(inf, min(sum[p << 1], sum[p << 1 | 1]) + tmp[p]);
}
void update(int p, int l, int r, int pos, long long int d) {
  if (l == r) {
    sum[p] = d;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(p << 1, l, mid, pos, d);
  else
    update(p << 1 | 1, mid + 1, r, pos, d);
  up(p);
}
long long int update(int p, int l, int r, int L, int R, long long int d) {
  if (l > R || r < L) return sum[p];
  if (L <= l && r <= R) {
    tmp[p] = min(inf, d + tmp[p]), sum[p] = min(inf, d + sum[p]);
    return sum[p];
  }
  int mid = (l + r) >> 1;
  sum[p] = min(update(p << 1, l, mid, L, R, d),
               update(p << 1 | 1, mid + 1, r, L, R, d)) +
           tmp[p];
  if (sum[p] > inf) sum[p] = inf;
  return sum[p];
}
long long int query(int p, int l, int r, int L, int R) {
  if (l > R || r < L) return inf;
  if (l == L && r == R) return sum[p];
  int mid = (l + r) / 2;
  if (R <= mid) return min(inf, query(p << 1, l, mid, L, R) + tmp[p]);
  if (mid < L) return min(inf, query(p << 1 | 1, mid + 1, r, L, R) + tmp[p]);
  return min(inf, min(query(p << 1, l, mid, L, mid),
                      query(p << 1 | 1, mid + 1, r, mid + 1, R)) +
                      tmp[p]);
}
long long int solve(int u, int fa) {
  long long int all = 0;
  for (int p = adj[u], v; p; p = edge[p].next)
    if ((v = edge[p].v) != fa) all = min(inf, all + solve(v, u));
  if (u == 1) return dp[u] = all;
  int p, v;
  for (p = in[u]; p; p = edge[p].next)
    update(1, 1, m, h[edge[p].v], w[edge[p].v] + all);
  for (p = out[u]; p; p = edge[p].next) update(1, 1, m, h[edge[p].v], inf);
  for (p = adj[u]; p; p = edge[p].next)
    if ((v = edge[p].v) != fa) update(1, 1, m, st[v], en[v], all - dp[v]);
  return dp[u] = query(1, 1, m, st[u], en[u]);
}
int main() {
  int u, v;
  GET(n), GET(m);
  for (int i = 1; i < n; ++i) {
    GET(u), GET(v);
    add(u, v, adj), add(v, u, adj);
  }
  for (int i = 1; i <= m; ++i) {
    GET(u), GET(v), GET(w[i]);
    add(u, i, in), add(v, i, out);
  }
  dfs(1, 0);
  long long int ans = solve(1, 0);
  printf("%I64d\n", ans >= inf ? -1 : ans);
  return 0;
}