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 = 3e5 + 7, M = N * 30;
const long long inf = 1e15;
int n, m, ch[M][2], tot;
long long mn[M], tag[M];
void add(int &id, int L, int R, int pos, long long w) {
  if (!id) id = ++tot, mn[id] = inf, tag[id] = 0;
  mn[id] = min(mn[id], w);
  if (L == R) return;
  int mid = (L + R) >> 1;
  if (pos <= mid)
    add(ch[id][0], L, mid, pos, w);
  else
    add(ch[id][1], mid + 1, R, pos, w);
}
void ad(int first, long long second) {
  if (first)
    mn[first] += second, mn[first] = min(mn[first], inf), tag[first] += second,
                         tag[first] = min(tag[first], inf);
}
void pushdown(int first) {
  ad(ch[first][0], tag[first]), ad(ch[first][1], tag[first]), tag[first] = 0;
}
void cover(int id, int L, int R, int pos) {
  if (!id) return;
  if (L == R) return mn[id] = inf, void();
  int mid = (L + R) >> 1;
  pushdown(id);
  if (pos <= mid)
    cover(ch[id][0], L, mid, pos);
  else
    cover(ch[id][1], mid + 1, R, pos);
  mn[id] = min(mn[ch[id][0]], mn[ch[id][1]]);
}
int merge(int first, int second, int L, int R, long long xr, long long yr) {
  if (!first || !second) {
    if (!first && !second) return 0;
    if (!first) return ad(second, xr), second;
    if (!second) return ad(first, yr), first;
  }
  if (L == R)
    return mn[first] = min(min(mn[first] + yr, mn[second] + xr),
                           min(mn[first] + mn[second], inf)),
           first;
  pushdown(first), pushdown(second);
  int mid = (L + R) >> 1;
  ch[first][0] = merge(ch[first][0], ch[second][0], L, mid,
                       min(xr, mn[ch[first][1]]), min(yr, mn[ch[second][1]]));
  ch[first][1] = merge(ch[first][1], ch[second][1], mid + 1, R, xr, yr);
  mn[first] = min(mn[ch[first][0]], mn[ch[first][1]]);
  return first;
}
int ehd[N], dep[N], enx[N << 1], ev[N << 1], eid, hd[N];
void eadd(int u, int v) { ++eid, enx[eid] = ehd[u], ev[eid] = v, ehd[u] = eid; }
void dfs(int first, int fa) {
  for (int i = ehd[first]; i; i = enx[i])
    if (ev[i] != fa) dep[ev[i]] = dep[first] + 1, dfs(ev[i], first);
}
void Dfs(int first, int fa) {
  if (enx[ehd[first]] || first == 1) {
    int cnt = 0, v = 0;
    for (int i = ehd[first]; i; i = enx[i])
      if (ev[i] != fa) cnt++, v = ev[i];
    if (cnt == 1)
      Dfs(v, first), hd[first] = merge(hd[first], hd[v], 1, n, 0ll, inf);
    else {
      add(hd[first], 1, n, dep[first], 0);
      for (int i = ehd[first]; i; i = enx[i])
        if (ev[i] != fa)
          Dfs(ev[i], first),
              hd[first] = merge(hd[first], hd[ev[i]], 1, n, inf, inf);
    }
  }
  if (first > 1) cover(hd[first], 1, n, dep[first]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m, mn[0] = inf;
  for (int i = 1, iE = n - 1; i <= iE; i++) {
    int u, v;
    cin >> u >> v;
    eadd(u, v), eadd(v, u);
  }
  dep[1] = 1, dfs(1, 0);
  for (int i = 1, iE = m; i <= iE; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    add(hd[u], 1, n, dep[v], w);
  }
  Dfs(1, 0);
  if (mn[hd[1]] >= inf)
    cout << "-1\n";
  else
    cout << mn[hd[1]] << "\n";
  return 0;
}