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 n, m, val[300050], st[300050], en[300050], id[300050], idcnt;
vector<int> adj[300050], ins[300050], del[300050];
long long lazy[300050 << 2], res[300050 << 2], ans[300050];
void dfs(int u, int fa) {
  st[u] = idcnt + 1;
  for (auto x : ins[u]) id[x] = ++idcnt;
  for (auto v : adj[u])
    if (v != fa) dfs(v, u);
  en[u] = idcnt;
}
void build(int u, int l, int r) {
  res[u] = (1LL << 50);
  if (l == r) return;
  build(u << 1, l, ((l + r) >> 1)), build(u << 1 | 1, ((l + r) >> 1) + 1, r);
}
inline void chk(long long &x) {
  if (x > (1LL << 50)) x = (1LL << 50);
}
void add(int u, long long w) {
  res[u] += w, chk(res[u]), lazy[u] += w, chk(lazy[u]);
}
void push(int u) {
  if (lazy[u]) add(u << 1, lazy[u]), add(u << 1 | 1, lazy[u]), lazy[u] = 0;
}
void change(int u, int l, int r, int x, long long w) {
  if (l == r) return void(res[u] = w);
  push(u);
  if (x <= ((l + r) >> 1))
    change(u << 1, l, ((l + r) >> 1), x, w);
  else
    change(u << 1 | 1, ((l + r) >> 1) + 1, r, x, w);
  res[u] = min(res[u << 1], res[u << 1 | 1]), chk(res[u]);
}
void modify(int u, int l, int r, int tl, int tr, long long w) {
  if (tl <= l && r <= tr) return add(u, w);
  push(u);
  if (tl <= ((l + r) >> 1)) modify(u << 1, l, ((l + r) >> 1), tl, tr, w);
  if (((l + r) >> 1) < tr) modify(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr, w);
  res[u] = min(res[u << 1], res[u << 1 | 1]), chk(res[u]);
}
long long query(int u, int l, int r, int tl, int tr) {
  if (tl > tr) return (1LL << 50);
  if (tl <= l && r <= tr) return res[u];
  push(u);
  long long ret = (1LL << 50);
  if (tl <= ((l + r) >> 1)) ret = query(u << 1, l, ((l + r) >> 1), tl, tr);
  if (((l + r) >> 1) < tr)
    ret = min(ret, query(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr));
  return ret;
}
void solve(int u, int fa) {
  long long cur = 0;
  for (auto v : adj[u]) {
    if (v != fa) solve(v, u), cur += ans[v], cur = min(cur, 3 * (1LL << 50));
  }
  if (u == 1) return void(ans[1] = cur);
  for (auto x : ins[u]) change(1, 1, m, id[x], cur + val[x]);
  for (auto x : del[u]) change(1, 1, m, id[x], (1LL << 50));
  for (auto v : adj[u]) {
    if (v != fa) modify(1, 1, m, st[v], en[v], cur - ans[v]);
  }
  ans[u] = query(1, 1, m, st[u], en[u]);
}
int main() {
  int u, v, w;
  scanf("%d%d", &n, &m);
  for (register int i = 1; i < n; ++i)
    scanf("%d%d", &u, &v), adj[u].push_back(v), adj[v].push_back(u);
  for (register int i = 1; i <= m; ++i)
    scanf("%d%d%d", &u, &v, &w), val[i] = w, ins[u].push_back(i),
                                 del[v].push_back(i);
  dfs(1, 0);
  build(1, 1, m);
  solve(1, 0);
  cout << (ans[1] >= (1LL << 50) ? -1 : ans[1]);
  return 0;
}