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 N = 3e5 + 100, S = 4 * N;
const long long INF = 1e16;
long long n, m;
long long c[N], dp[N];
long long s[N], e[N], id[N], T;
vector<long long> add[N], rem[N], G[N];
void dfs(long long u, long long p) {
  s[u] = T;
  for (long long x : add[u]) id[x] = T++;
  for (long long v : G[u])
    if (v != p) dfs(v, u);
  e[u] = T;
}
bool act[N];
long long mn[S], ex[S];
void pull(long long x, long long xl, long long xr) {
  mn[x] = (xr - xl > 1 ? min(mn[2 * x], mn[2 * x + 1]) + ex[x]
                       : (act[xl] ? ex[x] : INF));
}
void setactive(long long q, bool qv, long long x = 1, long long xl = 0,
               long long xr = T) {
  if (xr - xl == 1) {
    act[xl] = qv;
    pull(x, xl, xr);
    return;
  }
  long long mid = (xl + xr) / 2, l = 2 * x, r = l + 1;
  if (q < mid)
    setactive(q, qv, l, xl, mid);
  else
    setactive(q, qv, r, mid, xr);
  pull(x, xl, xr);
}
void upd(long long ql, long long qr, long long q, long long x = 1,
         long long xl = 0, long long xr = T) {
  if (xr <= ql || xl >= qr) return;
  if (xl >= ql && xr <= qr) {
    ex[x] += q;
    pull(x, xl, xr);
    return;
  }
  long long mid = (xl + xr) / 2, l = 2 * x, r = l + 1;
  upd(ql, qr, q, l, xl, mid);
  upd(ql, qr, q, r, mid, xr);
  pull(x, xl, xr);
}
long long get(long long ql, long long qr, long long x = 1, long long xl = 0,
              long long xr = T) {
  if (ql >= xr || qr <= xl) return INF;
  if (xl >= ql && xr <= qr) return mn[x];
  long long mid = (xl + xr) / 2, l = 2 * x, r = l + 1;
  return min(get(ql, qr, l, xl, mid), get(ql, qr, r, mid, xr)) + ex[x];
}
void solve(long long u, long long p) {
  for (long long v : G[u])
    if (v != p) solve(v, u);
  for (long long x : add[u])
    setactive(id[x], true), upd(id[x], id[x] + 1, c[x]);
  for (long long x : rem[u]) setactive(id[x], false);
  if (p != -1) {
    for (long long v : G[u])
      if (v != p) {
        upd(s[u], e[u], dp[v]);
        upd(s[v], e[v], -dp[v]);
      }
    dp[u] = get(s[u], e[u]);
  } else
    for (long long v : G[u]) dp[u] += dp[v];
  if (dp[u] >= INF / 2) {
    cout << -1;
    exit(0);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v >> c[i];
    u--;
    v--;
    add[u].push_back(i);
    rem[v].push_back(i);
  }
  dfs(0, -1);
  solve(0, -1);
  cout << dp[0] << endl;
}