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;
vector<int> e[300050], in[300050], out[300050];
int cost[300050], fa[300050];
long long minn[1200050], lazy[1200050];
int L[300050], R[300050];
int pcnt;
int P[300050];
void dfs(int pos) {
  L[pos] = pcnt + 1;
  for (int i = 0; i < in[pos].size(); ++i) P[in[pos][i]] = ++pcnt;
  for (int i = 0; i < e[pos].size(); ++i)
    if (e[pos][i] != fa[pos]) fa[e[pos][i]] = pos, dfs(e[pos][i]);
  R[pos] = pcnt;
}
void Update(int l, int r, int rt, int tar, long long val) {
  if (l == r) {
    minn[rt] = val;
    lazy[rt] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= tar)
    Update(l, mid, rt << 1, tar, val);
  else
    Update(mid + 1, r, rt << 1 | 1, tar, val);
  minn[rt] =
      min(min(minn[rt << 1], minn[rt << 1 | 1]) + lazy[rt], 1000000000000007ll);
}
void add(int l, int r, int rt, int ll, int rr, long long val) {
  if (l >= ll && r <= rr) {
    minn[rt] += val;
    lazy[rt] += val;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= ll) add(l, mid, rt << 1, ll, rr, val);
  if (mid < rr) add(mid + 1, r, rt << 1 | 1, ll, rr, val);
  minn[rt] =
      min(min(minn[rt << 1], minn[rt << 1 | 1]) + lazy[rt], 1000000000000007ll);
}
long long Query(int l, int r, int rt, int ll, int rr) {
  if (ll > rr) return 1000000000000007ll;
  if (l >= ll && r <= rr) return minn[rt];
  int mid = (l + r) >> 1;
  long long ans = 1000000000000007ll;
  if (mid >= ll) ans = min(ans, Query(l, mid, rt << 1, ll, rr));
  if (mid < rr) ans = min(ans, Query(mid + 1, r, rt << 1 | 1, ll, rr));
  return min(1000000000000007ll, ans + lazy[rt]);
}
long long dp[300050];
void do_the_dp(int pos) {
  long long cur = 0;
  for (int i = 0; i < e[pos].size(); ++i) {
    int v = e[pos][i];
    if (v != fa[pos]) {
      do_the_dp(v);
      cur = min(cur + dp[v], 1000000000000007ll);
    }
  }
  if (pos == 1) {
    dp[pos] = cur;
    return;
  }
  for (int i = 0; i < in[pos].size(); ++i) {
    int v = in[pos][i];
    Update(1, m, 1, P[v], cur + cost[v]);
  }
  for (int i = 0; i < out[pos].size(); ++i) {
    int v = out[pos][i];
    Update(1, m, 1, P[v], 1000000000000007ll);
  }
  for (int i = 0; i < e[pos].size(); ++i) {
    int v = e[pos][i];
    if (v != fa[pos]) add(1, m, 1, L[v], R[v], cur - dp[v]);
  }
  dp[pos] = min(1000000000000007ll, Query(1, m, 1, L[pos], R[pos]));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d%lld", &u, &v, &cost[i]);
    in[u].push_back(i);
    out[v].push_back(i);
  }
  for (int i = 1; i <= m * 4; ++i) lazy[i] = 0, minn[i] = 1000000000000007ll;
  dfs(1);
  do_the_dp(1);
  if (dp[1] == 1000000000000007ll)
    printf("-1\n");
  else
    printf("%lld\n", dp[1]);
}