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;
struct node {
  long long val, lazy;
  node() { val = lazy = 0; }
};
node tre[3 * 400005];
void propagete(long long n, long long l, long long r) {
  tre[n].val += tre[n].lazy;
  if (l != r) {
    tre[2 * n].lazy += tre[n].lazy;
    tre[2 * n + 1].lazy += tre[n].lazy;
  }
  tre[n].lazy = 0;
}
long long combine(long long a, long long b) { return min(a, b); }
void init(long long n, long long l, long long r) {
  if (l == r) {
    tre[n].val = 1LL << 50;
    return;
  }
  long long mid = (l + r) / 2;
  init(2 * n, l, mid);
  init(2 * n + 1, mid + 1, r);
  tre[n].val = combine(tre[2 * n].val, tre[2 * n + 1].val);
}
void update(long long n, long long l, long long r, long long i, long long j,
            long long val) {
  if (i > j) return;
  propagete(n, l, r);
  if (l > j || r < i) return;
  if (i <= l && j >= r) {
    tre[n].lazy += val;
    propagete(n, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  update(2 * n, l, mid, i, j, val);
  update(2 * n + 1, mid + 1, r, i, j, val);
  tre[n].val = combine(tre[2 * n].val, tre[2 * n + 1].val);
}
long long query(long long n, long long l, long long r, long long i,
                long long j) {
  propagete(n, l, r);
  if (i > j) return (1LL << 55);
  if (l > j || r < i) return (1LL << 55);
  if (i <= l && j >= r) {
    return tre[n].val;
  }
  long long mid = (l + r) / 2;
  return combine(query(2 * n, l, mid, i, j),
                 query(2 * n + 1, mid + 1, r, i, j));
}
long long st[400005], idx[400005], ed[400005];
long long T;
vector<long long> adj[400005], upre[400005], niche[400005];
long long arr[400005];
long long dp[400005];
void dfs(long long n, long long par = 0) {
  st[n] = T;
  for (auto &cv : niche[n]) {
    idx[cv] = T++;
  }
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    dfs(cv, n);
  }
  ed[n] = T;
}
long long sol(long long n, long long par) {
  long long chlds = 0;
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    chlds += sol(cv, n);
    chlds = min(chlds, 1LL << 55);
  }
  if (n == 1) return dp[n] = chlds;
  for (auto &cv : upre[n]) update(1, 0, T, idx[cv], idx[cv], 1LL << 55);
  for (auto &cv : adj[n]) {
    if (cv == par) continue;
    update(1, 0, T, st[cv], ed[cv] - 1, chlds - dp[cv]);
  }
  for (auto &cv : niche[n]) {
    update(1, 0, T, idx[cv], idx[cv],
           chlds + arr[cv] - query(1, 0, T, idx[cv], idx[cv]));
  }
  return dp[n] = query(1, 0, T, st[n], ed[n] - 1);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y >> arr[i];
    upre[y].push_back(i);
    niche[x].push_back(i);
  }
  dfs(1);
  init(1, 0, T);
  long long ans = sol(1, 0);
  if (ans >= 1000000000000000) ans = -1;
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}