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, head[300010], o = 0, root[300010], id = 0, lc[6000010], rc[6000010],
                        st[6000010], up = 0, dep[300010], siz[6000010];
long long tree[6000010], add[6000010];
struct point {
  int fa, w;
};
int new_node() {
  int tmp = up ? st[up--] : ++id;
  tree[tmp] = add[tmp] = 1e17;
  return tmp;
}
void delte(int u) {
  tree[u] = 1e17, lc[u] = rc[u] = add[u] = siz[u] = 0;
  st[++up] = u;
}
vector<point> pos[300010];
struct edge {
  int to, link;
} e[600010];
void add_edge(int u, int v) {
  e[++o].to = v, e[o].link = head[u], head[u] = o;
  e[++o].to = u, e[o].link = head[v], head[v] = o;
}
void pushdown(int t) {
  if (lc[t]) {
    tree[lc[t]] += add[t];
    add[lc[t]] += add[t];
  }
  if (rc[t]) {
    tree[rc[t]] += add[t];
    add[rc[t]] += add[t];
  }
  add[t] = 0;
}
void add_tree(int &t, int a, int l, int r, long long c) {
  if (!t) t = new_node(), siz[t] = 1;
  tree[t] = min(tree[t], c);
  if (l == r) return;
  pushdown(t);
  int mid = (l + r) >> 1;
  if (mid >= a)
    add_tree(lc[t], a, l, mid, c);
  else
    add_tree(rc[t], a, mid + 1, r, c);
  siz[t] = siz[lc[t]] + siz[rc[t]];
}
long long query(int &t, int ll, int rr, int l, int r) {
  if (!t) return 1e17;
  if (ll <= l && r <= rr) return tree[t];
  pushdown(t);
  int mid = (l + r) >> 1;
  if (mid < ll) return query(rc[t], ll, rr, mid + 1, r);
  if (rr <= mid) return query(lc[t], ll, rr, l, mid);
  return min(query(lc[t], ll, rr, l, mid), query(rc[t], ll, rr, mid + 1, r));
}
void merge(int &t, int &t2, int l, int r) {
  if (!t2) return;
  if (!t) t = new_node(), siz[t] = 1;
  if (siz[t] < siz[t2]) swap(t, t2);
  tree[t] = min(tree[t], tree[t2]);
  if (l == r) return delte(t2), void();
  int mid = (l + r) >> 1;
  pushdown(t);
  pushdown(t2);
  merge(lc[t], lc[t2], l, mid);
  merge(rc[t], rc[t2], mid + 1, r);
  delte(t2);
  siz[t] = siz[lc[t]] + siz[rc[t]];
}
void dfs(int u, int pre) {
  dep[u] = dep[pre] + 1;
  add_tree(root[u], dep[u], 1, n, 0);
  for (int i = head[u]; i; i = e[i].link) {
    if (e[i].to == pre) continue;
    dfs(e[i].to, u);
    long long tmp1 = query(root[u], 1, dep[u], 1, n),
              tmp2 = query(root[e[i].to], 1, dep[u], 1, n);
    if (root[u]) tree[root[u]] += tmp2, add[root[u]] += tmp2;
    if (root[e[i].to]) tree[root[e[i].to]] += tmp1, add[root[e[i].to]] += tmp1;
    merge(root[u], root[e[i].to], 1, n);
  }
  for (int i = 0; i < (signed)pos[u].size(); i++) {
    long long tmp = query(root[u], 1, dep[u], 1, n);
    add_tree(root[u], dep[pos[u][i].fa], 1, n, tmp + pos[u][i].w);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1, u, v; i < n; i++) scanf("%d %d", &u, &v), add_edge(u, v);
  for (int i = 1, s, t, z; i <= m; i++)
    scanf("%d %d %d", &s, &t, &z), pos[s].push_back((point){t, z});
  dfs(1, 0);
  long long tmp = query(root[1], 1, 1, 1, n);
  printf("%lld\n", tmp >= 1e16 || tmp < 0 ? -1 : tmp);
}