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 int maxn = 2e6;
const int maxv = 4e5;
const long long INF = 3e14 + 333;
struct Node {
  int u, v, c;
  void in() { scanf("%d%d%d", &u, &v, &c); }
} wo[maxn];
vector<int> G[maxv], st[maxv], ed[maxv];
int n, m;
int dfn = 0;
int d[maxv][2];
int wd[maxv];
void dfs(int v, int f) {
  d[v][0] = dfn;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == f) continue;
    dfs(u, v);
  }
  for (int i = 0; i < st[v].size(); i++) wd[st[v][i]] = dfn++;
  d[v][1] = dfn;
}
unsigned long long dp[maxn];
unsigned long long val[maxn], add[maxn];
void push(int o, int l, int r) {
  if (r - l <= 1 || !add[o]) return;
  val[((o << 1))] += add[o];
  val[((o << 1) | 1)] += add[o];
  add[((o << 1))] += add[o];
  add[((o << 1) | 1)] += add[o];
  add[o] = 0;
}
void change(int o, int p, int l, int r, unsigned long long x) {
  push(o, l, r);
  if (r - l <= 1) {
    val[o] = x;
    return;
  }
  if (p < ((r + l) >> 1))
    change(((o << 1)), p, l, ((r + l) >> 1), x);
  else
    change(((o << 1) | 1), p, ((r + l) >> 1), r, x);
  val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);
}
void Add(int o, int a, int b, int l, int r, unsigned long long x) {
  if (a >= r || b <= l) return;
  push(o, l, r);
  if (l >= a && r <= b) {
    val[o] += x;
    add[o] += x;
    return;
  }
  Add(((o << 1)), a, b, l, ((r + l) >> 1), x);
  Add(((o << 1) | 1), a, b, ((r + l) >> 1), r, x);
  val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);
}
unsigned long long rmq(int o, int a, int b, int l, int r) {
  if (a >= r || b <= l) return INF;
  push(o, l, r);
  if (l >= a && r <= b) return val[o];
  return min(rmq(((o << 1)), a, b, l, ((r + l) >> 1)),
             rmq(((o << 1) | 1), a, b, ((r + l) >> 1), r));
}
unsigned long long ans = 0;
void DP(int v, int f) {
  unsigned long long sum = 0;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == f) continue;
    DP(u, v);
    sum += dp[u];
  }
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == f) continue;
    Add(1, d[u][0], d[u][1], 0, m, sum - dp[u]);
  }
  for (int i = 0; i < st[v].size(); i++) {
    int w = st[v][i];
    change(1, wd[w], 0, m, sum + wo[w].c);
  }
  for (int i = 0; i < ed[v].size(); i++) {
    int w = ed[v][i];
    change(1, wd[w], 0, m, INF);
  }
  if (v == 1) ans = sum;
  dp[v] = rmq(1, d[v][0], d[v][1], 0, m);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 0; i < m; i++) {
    wo[i].in();
    st[wo[i].u].push_back(i);
    ed[wo[i].v].push_back(i);
  }
  for (int i = 0; i < m; i++) change(1, i, 0, m, INF);
  dfs(1, -1);
  DP(1, -1);
  if (ans >= INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}