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 = 300000 + 17;
const long long INF = LLONG_MAX >> 1;
vector<int> Adj[MAXN], A[MAXN], B[MAXN];
int n, m, st[MAXN], en[MAXN], id[MAXN], cost[MAXN], dt;
long long val[MAXN << 2], tag[MAXN << 2], res[MAXN];
void DFS(int u, int p) {
  st[u] = dt + 1;
  for (int i : A[u]) id[i] = ++dt;
  for (int v : Adj[u])
    if (v != p) DFS(v, u);
  en[u] = dt;
}
void Build(int rt, int l, int r) {
  val[rt] = INF;
  if (l != r) {
    int m = (l + r) >> 1;
    Build((rt << 1), l, m);
    Build((rt << 1 | 1), m + 1, r);
  }
}
void Update(int p, long long v, int rt, int l, int r) {
  if (l == r) {
    val[rt] = v;
    return;
  }
  int m = (l + r) >> 1;
  if (p <= m)
    Update(p, v, (rt << 1), l, m);
  else
    Update(p, v, (rt << 1 | 1), m + 1, r);
  val[rt] = min(INF, min(val[(rt << 1)], val[(rt << 1 | 1)]) + tag[rt]);
}
void Add(int al, int ar, long long v, int rt, int l, int r) {
  if (al > ar) return;
  if (al == l && ar == r) {
    val[rt] = min(val[rt] + v, INF);
    tag[rt] = min(tag[rt] + v, INF);
    return;
  }
  int m = (l + r) >> 1;
  if (ar <= m)
    Add(al, ar, v, (rt << 1), l, m);
  else if (al > m)
    Add(al, ar, v, (rt << 1 | 1), m + 1, r);
  else
    Add(al, m, v, (rt << 1), l, m), Add(m + 1, ar, v, (rt << 1 | 1), m + 1, r);
  val[rt] = min(INF, min(val[(rt << 1)], val[(rt << 1 | 1)]) + tag[rt]);
}
long long Query(int al, int ar, int rt, int l, int r) {
  if (al > ar) return INF;
  if (al == l && ar == r) return val[rt];
  int m = (l + r) >> 1;
  if (ar <= m)
    return min(INF, Query(al, ar, (rt << 1), l, m) + tag[rt]);
  else if (al > m)
    return min(INF, Query(al, ar, (rt << 1 | 1), m + 1, r) + tag[rt]);
  else
    return min(INF, min(Query(al, m, (rt << 1), l, m),
                        Query(m + 1, ar, (rt << 1 | 1), m + 1, r)) +
                        tag[rt]);
}
void Solve(int u, int p) {
  long long ans = 0;
  for (int v : Adj[u])
    if (v != p) {
      Solve(v, u);
      ans = min(ans + res[v], INF);
    }
  if (u == 1) {
    res[1] = ans;
    return;
  }
  for (int i : A[u]) Update(id[i], ans + cost[i], 1, 1, m);
  for (int i : B[u]) Update(id[i], INF, 1, 1, m);
  for (int v : Adj[u])
    if (v != p) Add(st[v], en[v], ans - res[v], 1, 1, m);
  res[u] = Query(st[u], en[u], 1, 1, m);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    Adj[u].push_back(v);
    Adj[v].push_back(u);
  }
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d%d", &l, &r, cost + i);
    A[l].push_back(i);
    B[r].push_back(i);
  }
  DFS(1, 0);
  Build(1, 1, m);
  Solve(1, 0);
  cout << (res[1] == INF ? -1 : res[1]) << "\n";
}