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 maxn = 3e5 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
struct TreeNode {
  long long ls, rs, mi, wv, val, dis, tag;
  TreeNode() { mi = inf; }
};
TreeNode t[maxn];
long long pol;
void pushup(long long p) {
  t[p].mi = min(t[t[p].ls].mi, min(t[t[p].rs].mi, t[p].val));
  return;
}
void lazy(long long p, long long k) {
  t[p].mi += k;
  t[p].val += k;
  return;
}
void pushdown(long long p) {
  t[t[p].ls].tag += t[p].tag;
  t[t[p].rs].tag += t[p].tag;
  lazy(t[p].ls, t[p].tag);
  lazy(t[p].rs, t[p].tag);
  t[p].tag = 0;
  return;
}
long long newnode(long long wv, long long val) {
  t[++pol].wv = wv;
  t[pol].ls = t[pol].rs = 0;
  t[pol].val = t[pol].mi = val;
  t[pol].dis = 0;
  return pol;
}
long long merge(long long x, long long y) {
  if (!x || !y) return x + y;
  if (t[x].wv < t[y].wv) swap(x, y);
  pushdown(x);
  t[x].rs = merge(t[x].rs, y);
  if (t[t[x].ls].dis < t[t[x].rs].dis) swap(t[x].ls, t[x].rs);
  t[x].dis = t[t[x].rs].dis + 1;
  pushup(x);
  return x;
}
vector<long long> adj[maxn];
vector<long long> cha[maxn], cst[maxn];
long long dep[maxn], rt[maxn], f[maxn];
void dfs(long long now, long long fa) {
  long long sum = 0;
  for (int i = 0; i < adj[now].size(); i++) {
    long long tt = adj[now][i];
    if (tt == fa) continue;
    dep[tt] = dep[now] + 1;
    dfs(tt, now);
    sum += f[tt];
    while (rt[tt] && now != 1 && t[rt[tt]].wv >= dep[now]) {
      pushdown(rt[tt]);
      rt[tt] = merge(t[rt[tt]].ls, t[rt[tt]].rs);
    }
  }
  for (int i = 0; i < adj[now].size(); i++) {
    long long tt = adj[now][i];
    if (tt == fa) continue;
    t[rt[tt]].tag += sum - f[tt];
    lazy(rt[tt], sum - f[tt]);
    rt[now] = merge(rt[now], rt[tt]);
  }
  for (int i = 0; i < cha[now].size(); i++) {
    long long y = cha[now][i];
    if (y == now) continue;
    long long co = cst[now][i];
    rt[now] = merge(rt[now], newnode(dep[y], sum + co));
  }
  if (!rt[now]) {
    puts("-1");
    exit(0);
  }
  f[now] = t[rt[now]].mi;
  return;
}
long long n, m;
int main() {
  scanf("%lld %lld", &n, &m);
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    long long ux, vx;
    scanf("%lld %lld", &ux, &vx);
    adj[ux].push_back(vx);
    adj[vx].push_back(ux);
  }
  for (int i = 1; i <= m; i++) {
    long long ux, vx, cx;
    scanf("%lld %lld %lld", &ux, &vx, &cx);
    cha[ux].push_back(vx);
    cst[ux].push_back(cx);
  }
  dfs(1, 0);
  printf("%lld\n", f[1]);
  return 0;
}