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;
inline int ty() {
  register int a = 0, b = 1, c = getchar();
  while (!isdigit(c)) b ^= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return b ? a : -a;
}
const int _ = 300007, __ = _ << 1;
int to[__], ne[__], he[_] = {0}, ecnt = 1;
void adde(int a, int b) { to[++ecnt] = b, ne[ecnt] = he[a], he[a] = ecnt; }
void addde(int a, int b) { adde(a, b), adde(b, a); }
int n, m, dep[_] = {0}, sval[_] = {0};
void dfs(int x, int ff) {
  dep[x] = dep[ff] + 1;
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b == ff) continue;
    dfs(b, x), sval[x] += sval[b];
  }
}
struct node {
  int lc, rc, dep;
  int val, tag, las;
  node(int _lc = 0, int _rc = 0, int _dep = 0, int _val = 0, int _tag = 0,
       int _las = 0) {
    lc = _lc, rc = _rc, dep = _dep, val = _val, tag = _tag, las = _las;
  }
} t[_];
int rt[_];
void puttag(int x, int dlt) {
  if (x) t[x].val += dlt, t[x].tag += dlt;
}
void dwn(int x) {
  if (!t[x].tag) return;
  if (t[x].lc) puttag(t[x].lc, t[x].tag);
  if (t[x].rc) puttag(t[x].rc, t[x].tag);
  t[x].tag = 0;
}
int merges(int l, int r) {
  if (!l || !r) return l + r;
  dwn(l), dwn(r);
  if (t[l].val > t[r].val) swap(l, r);
  t[l].rc = merges(t[l].rc, r);
  if (t[t[l].lc].dep < t[t[l].rc].dep) swap(t[l].lc, t[l].rc);
  t[l].dep = t[t[l].rc].dep + 1;
  return l;
}
long long ans = 0;
void dfs2(int x, int ff) {
  for (int i = he[x]; i; i = ne[i]) {
    int b = to[i];
    if (b == ff) continue;
    dfs2(b, x), rt[x] = merges(rt[x], rt[b]);
  }
  if (x == 1) return;
  while (dep[t[rt[x]].las] >= dep[x]) rt[x] = merges(t[rt[x]].lc, t[rt[x]].rc);
  int dlt = t[rt[x]].val;
  ans += dlt, puttag(rt[x], -dlt);
}
int pst[_], ped[_], pco[_];
int main() {
  n = ty(), m = ty();
  for (register int i = 1; i < n; i++) {
    register int a = ty(), b = ty();
    addde(a, b);
  }
  for (register int i = 1; i <= m; i++)
    pst[i] = ty(), ped[i] = ty(), pco[i] = ty(), sval[pst[i]]++, sval[ped[i]]--;
  dfs(1, 0);
  for (register int i = 2; i <= n; i++)
    if (sval[i] <= 0) {
      puts("-1");
      return 0;
    }
  for (register int i = 1; i <= m; i++)
    t[i] = node(0, 0, 0, pco[i], 0, ped[i]), rt[pst[i]] = merges(rt[pst[i]], i);
  dfs2(1, 0), printf("%lld\n", ans);
  return 0;
}