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 N = 7e5;
struct Node {
  long long w;
  int dep, ch[2], dis;
} a[N];
struct INFOR {
  long long w;
  int dep;
} f[N];
long long tag[N];
int node_cnt, dep[N], to[N], fst[N], nxt[N], mm, n, m, root[N];
vector<pair<int, int> > chain[N];
void ade(int u, int v) { to[++mm] = v, nxt[mm] = fst[u], fst[u] = mm; }
void upd(int u, long long w) { tag[u] += w, a[u].w += w; }
void pushdown(int u) {
  if (a[u].ch[0]) upd(a[u].ch[0], tag[u]);
  if (a[u].ch[1]) upd(a[u].ch[1], tag[u]);
  tag[u] = 0;
}
int merge(int u, int v) {
  if (!u || !v) return u | v;
  if (a[u].w > a[v].w) swap(u, v);
  pushdown(u);
  a[u].ch[1] = merge(a[u].ch[1], v);
  if (a[a[u].ch[1]].dis > a[a[u].ch[0]].dis) swap(a[u].ch[0], a[u].ch[1]);
  a[u].dis = a[a[u].ch[1]].dis + 1;
  return u;
}
int newnode(long long w, int dep) {
  int u = ++node_cnt;
  a[u].w = w, a[u].dep = dep, a[u].ch[0] = a[u].ch[1] = a[u].dis = tag[u] = 0;
  return u;
}
void ins(int &u, long long w, int dep) { u = merge(u, newnode(w, dep)); }
void pop(int &u) {
  pushdown(u);
  u = merge(a[u].ch[0], a[u].ch[1]);
}
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  long long sf = 0;
  int mindep = n;
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(v, u);
    sf += f[v].w, mindep = min(mindep, f[v].dep);
  }
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    upd(root[v], sf - f[v].w);
    root[u] = merge(root[u], root[v]);
  }
  if (u == 1) {
    cout << sf << endl;
    exit(0);
  }
  for (vector<pair<int, int> >::iterator it = chain[u].begin();
       it != chain[u].end(); ++it)
    ins(root[u], sf + it->second, min(mindep, dep[it->first]));
  while (root[u] && a[root[u]].dep >= dep[u]) pop(root[u]);
  if (!root[u]) {
    puts("-1");
    exit(0);
  }
  f[u].w = a[root[u]].w, f[u].dep = a[root[u]].dep;
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == 1) {
    puts("0");
    return 0;
  }
  for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), ade(u, v), ade(v, u);
  for (int i = 1, x, y, w; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &w);
    if (x == y) continue;
    chain[x].push_back(make_pair(y, w));
  }
  a[0].dis = -1;
  dfs(1, 0);
}