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;
using LL = long long;
constexpr LL INF = 1E15;
constexpr int M = 1 << 20;
struct Node {
  LL mn, lazy;
} t[M];
void build(int p, int l, int r) {
  t[p].mn = INF;
  if (r - l == 1) return;
  int mid = (l + r) / 2;
  build(2 * p, l, mid);
  build(2 * p + 1, mid, r);
}
void pushdown(int p) {
  t[2 * p].mn = min(INF, t[2 * p].mn + t[p].lazy);
  t[2 * p].lazy = min(INF, t[2 * p].lazy + t[p].lazy);
  t[2 * p + 1].mn = min(INF, t[2 * p + 1].mn + t[p].lazy);
  t[2 * p + 1].lazy = min(INF, t[2 * p + 1].lazy + t[p].lazy);
  t[p].lazy = 0;
}
void pushup(int p) { t[p].mn = min(t[2 * p].mn, t[2 * p + 1].mn); }
void modify(int p, int l, int r, int x, LL v) {
  if (r - l == 1) {
    t[p].mn = v;
    return;
  }
  int mid = (l + r) / 2;
  pushdown(p);
  if (x < mid)
    modify(2 * p, l, mid, x, v);
  else
    modify(2 * p + 1, mid, r, x, v);
  pushup(p);
}
void rangeAdd(int p, int l, int r, int x, int y, LL v) {
  if (l >= y || r <= x) return;
  if (l >= x && r <= y) {
    t[p].mn = min(INF, t[p].mn + v);
    t[p].lazy = min(INF, t[p].lazy + v);
    return;
  }
  int mid = (l + r) / 2;
  pushdown(p);
  rangeAdd(2 * p, l, mid, x, y, v);
  rangeAdd(2 * p + 1, mid, r, x, y, v);
  pushup(p);
}
LL rangeMin(int p, int l, int r, int x, int y) {
  if (l >= y || r <= x) return INF;
  if (l >= x && r <= y) return t[p].mn;
  int mid = (l + r) / 2;
  pushdown(p);
  return min(rangeMin(2 * p, l, mid, x, y), rangeMin(2 * p + 1, mid, r, x, y));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  build(1, 0, m);
  vector<vector<int>> e(n), add(n), del(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    e[--u].push_back(--v);
    e[v].push_back(u);
  }
  vector<int> in(n), out(n);
  int dfs_now = 0;
  function<void(int, int)> dfs = [&](int u, int p) {
    in[u] = dfs_now++;
    for (int v : e[u])
      if (v != p) dfs(v, u);
    out[u] = dfs_now;
  };
  dfs(0, -1);
  vector<tuple<int, int, int>> q(m);
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    q[i] = {--u, --v, c};
  }
  sort(q.begin(), q.end(),
       [&](const tuple<int, int, int> &i, const tuple<int, int, int> &j) {
         return in[get<0>(i)] < in[get<0>(j)];
       });
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    tie(u, v, c) = q[i];
    add[u].push_back(i);
    del[v].push_back(i);
  }
  vector<LL> dp(n);
  vector<int> st(n + 1);
  for (int i = 0, j = 0; i <= n; ++i) {
    while (j < m && in[get<0>(q[j])] < i) ++j;
    st[i] = j;
  }
  function<void(int, int)> solve = [&](int u, int p) {
    LL sum = 0;
    for (int v : e[u]) {
      if (v == p) continue;
      solve(v, u);
      sum = min(INF, sum + dp[v]);
    }
    if (u == 0) {
      dp[u] = sum;
      return;
    }
    for (int i : add[u]) modify(1, 0, m, i, min(INF, get<2>(q[i]) + sum));
    for (int i : del[u]) modify(1, 0, m, i, INF);
    for (int v : e[u])
      if (v != p) rangeAdd(1, 0, m, st[in[v]], st[out[v]], sum - dp[v]);
    dp[u] = rangeMin(1, 0, m, st[in[u]], st[out[u]]);
  };
  solve(0, -1);
  if (dp[0] == INF)
    cout << -1 << "\n";
  else
    cout << dp[0] << "\n";
  return 0;
}