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;
int const N = 1e6 + 7;
long long const oo = 1e15 + 5;
long long dp[N];
int n, m, u, v, c[N], idx[N], ds[N], de[N], t;
vector<int> tree[N], wf[N], wt[N];
struct Node {
  long long min, lazy;
} seg[N << 2];
void dfs(int cur = 1, int par = 0) {
  ds[cur] = t + 1;
  for (int i = 0; i < wf[cur].size(); i++) idx[wf[cur][i]] = ++t;
  for (int i = 0, to; i < tree[cur].size(); i++)
    if ((to = tree[cur][i]) != par) dfs(to, cur);
  de[cur] = t;
}
inline void down(int rt) {
  if (seg[rt].lazy) {
    long long lazy = seg[rt].lazy;
    seg[rt << 1].min = min(seg[rt << 1].min + lazy, oo);
    seg[rt << 1 | 1].min = min(seg[rt << 1 | 1].min + lazy, oo);
    seg[rt << 1].lazy = min(seg[rt << 1].lazy + lazy, oo);
    seg[rt << 1 | 1].lazy = min(seg[rt << 1 | 1].lazy + lazy, oo);
    seg[rt].lazy = 0;
  }
}
inline void up(int rt) {
  seg[rt].min = min(oo, min(seg[rt << 1].min, seg[rt << 1 | 1].min));
}
void add(int L, int R, long long v, int l = 1, int r = m, int rt = 1) {
  if (L <= l && R >= r) {
    seg[rt].min = min(seg[rt].min + v, oo);
    seg[rt].lazy = min(seg[rt].lazy + v, oo);
    assert(seg[rt].min > 0 && seg[rt].lazy >= 0);
    return;
  }
  down(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) add(L, R, v, l, mid, rt << 1);
  if (R > mid) add(L, R, v, mid + 1, r, rt << 1 | 1);
  up(rt);
}
void update(int p, long long v, int l = 1, int r = m, int rt = 1) {
  if (l == r) {
    seg[rt].min = v;
    seg[rt].lazy = 0;
    return;
  }
  down(rt);
  int mid = (l + r) >> 1;
  if (p <= mid)
    update(p, v, l, mid, rt << 1);
  else
    update(p, v, mid + 1, r, rt << 1 | 1);
  up(rt);
}
long long query(int L, int R, int l = 1, int r = m, int rt = 1) {
  if (L <= l && R >= r) {
    assert(seg[rt].min > 0);
    return seg[rt].min;
  }
  down(rt);
  int mid = (l + r) >> 1;
  long long lv = oo, rv = oo;
  if (L <= mid) lv = query(L, R, l, mid, rt << 1);
  if (R > mid) rv = query(L, R, mid + 1, r, rt << 1 | 1);
  return min(lv, rv);
}
long long solve(int cur = 1, int par = 1) {
  long long sum = 0;
  for (int i = 0, to; i < tree[cur].size(); i++)
    if ((to = tree[cur][i]) != par) {
      sum += solve(to, cur);
      sum = min(sum, oo);
    }
  if (cur == 1) return (dp[1] = sum) == oo ? -1 : sum;
  for (int i = 0, ci; i < wf[cur].size(); i++) {
    ci = wf[cur][i];
    update(idx[ci], min(sum + c[ci], oo));
  }
  for (int i = 0; i < wt[cur].size(); i++) update(idx[wt[cur][i]], oo);
  for (int i = 0, to; i < tree[cur].size(); i++)
    if ((to = tree[cur][i]) != par)
      add(ds[to], de[to], (sum == oo || dp[to] == oo) ? oo : (sum - dp[to]));
  dp[cur] = min(query(ds[cur], de[cur]), oo);
  assert(dp[cur] > 0);
  return dp[cur];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> c[i];
    wf[u].push_back(i);
    wt[v].push_back(i);
  }
  int max_son = 0;
  for (int i = 1; i < n; i++) max_son = max(int(tree[i].size()), max_son);
  if (max_son - 1 > m) {
    cout << -1 << endl;
  } else {
    dfs();
    add(1, m, oo);
    cout << solve() << endl;
  }
  return 0;
}