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 oo = 1e15;
const int maxn = 7e5, maxm = 3e6;
struct worker {
  int u, v, c;
} W[maxn];
struct node {
  long long v;
  int i;
  bool operator<(const node &a) const { return v > a.v; }
};
vector<int> g[maxn];
vector<int> U[maxn];
vector<int> V[maxn];
priority_queue<node> Q[maxn];
long long a[maxm], Z[maxm];
long long dp[maxn], sum[maxn];
int X[maxn][2], Y[maxn], b[maxn];
long long ans;
int n, m, i, j, x, y, z, tot, top, L, R, bl;
void dfs(int o, int fa) {
  X[o][0] = ++tot;
  Y[tot] = o;
  int len = g[o].size(), i;
  for (i = 0; i < len; i++) {
    int v = g[o][i];
    if (v == fa) continue;
    dfs(v, o);
  }
  X[o][1] = ++tot;
  Y[tot] = o;
}
void update(int o) {
  a[o] = min(a[2 * o] + Z[2 * o], a[2 * o + 1] + Z[2 * o + 1]);
  a[o] = min(a[o], oo);
}
void build(int o, int l, int r) {
  if (l + 1 == r) {
    a[o] = oo;
    return;
  }
  int m = (l + r) >> 1;
  build(2 * o, l, m);
  build(2 * o + 1, m, r);
  update(o);
}
void pushdown(int o) {
  Z[2 * o] += Z[o];
  Z[2 * o + 1] += Z[o];
  Z[o] = 0;
}
void change(int o, int l, int r, int v) {
  if (l + 1 == r) {
    a[o] = oo;
    while (!Q[l].empty() && b[Q[l].top().i]) Q[l].pop();
    if (!Q[l].empty()) a[o] = Q[l].top().v;
    return;
  }
  pushdown(o);
  int m = (l + r) >> 1;
  if (v < m)
    change(2 * o, l, m, v);
  else
    change(2 * o + 1, m, r, v);
  update(o);
}
void find(int o, int l, int r, int x, int y, long long &re) {
  if (x <= l && r <= y) {
    re = min(re, a[o] + Z[o]);
    return;
  }
  pushdown(o);
  int m = (l + r) >> 1;
  if (x < m) find(2 * o, l, m, x, y, re);
  if (m < y) find(2 * o + 1, m, r, x, y, re);
  update(o);
}
void put(int o, int l, int r, int x, int y, long long v) {
  if (x <= l && r <= y) {
    Z[o] += v;
    return;
  }
  pushdown(o);
  int m = (l + r) >> 1;
  if (x < m) put(2 * o, l, m, x, y, v);
  if (m < y) put(2 * o + 1, m, r, x, y, v);
  update(o);
}
void get(int o, int fa) {
  int len = g[o].size(), i;
  for (i = 0; i < len; i++) {
    int v = g[o][i];
    if (v == fa) continue;
    get(v, o);
    if (!bl) return;
    sum[o] += dp[v];
  }
  while ((len = U[o].size())) {
    i = U[o][len - 1];
    U[o].pop_back();
    Q[X[o][0]].push((node){W[i].c + sum[o], i});
  }
  change(1, L, R, X[o][0]);
  if (o != 1)
    while ((len = V[o].size())) {
      i = V[o][len - 1];
      V[o].pop_back();
      b[i] = 1;
      change(1, L, R, X[W[i].u][0]);
    }
  len = g[o].size();
  for (i = 0; i < len; i++) {
    int v = g[o][i];
    if (v == fa) continue;
    put(1, L, R, X[v][0], X[v][1] + 1, sum[o] - dp[v]);
  }
  dp[o] = oo;
  find(1, L, R, X[o][0], X[o][1] + 1, dp[o]);
  if (dp[o] == oo) {
    bl = 0;
    return;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    W[i] = (worker){x, y, z};
    U[x].push_back(i);
    V[y].push_back(i);
  }
  if (n == 1) {
    printf("0");
    return 0;
  }
  ans = oo;
  dfs(1, 0);
  L = 1;
  R = tot + 1;
  build(1, L, R);
  bl = 1;
  get(1, 0);
  ans = dp[1];
  if (!bl) ans = -1;
  printf("%I64d", ans);
  return 0;
}