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 = 300050;
const long long inf = 1e15;
int nxt[Maxn << 1], head[Maxn], to[Maxn << 1], cnt;
void AddEdge(int u, int v) { nxt[++cnt] = head[u], head[u] = cnt, to[cnt] = v; }
int in[Maxn], out[Maxn], dfn;
class Farm {
 public:
  int id, c;
  Farm(int _id = 0, int _c = 0) { id = _id, c = _c; }
};
vector<Farm> add[Maxn], del[Maxn];
int pos[Maxn];
void dfs(int u, int v) {
  in[u] = dfn;
  for (int i = 0; i < add[u].size(); ++i) pos[add[u][i].id] = ++dfn;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != v) dfs(to[i], u);
  out[u] = dfn;
}
class Node {
 public:
  int l, r;
  long long mn, lazy;
} v[Maxn << 3];
int here[Maxn];
void push_down(int node) {
  if (v[node].lazy) {
    if (v[node].lazy > inf) v[node].lazy = inf;
    v[node].mn += v[node].lazy;
    v[node << 1].lazy += v[node].lazy, v[(node << 1) | 1].lazy += v[node].lazy;
    v[node].lazy = 0;
  }
}
void push_up(int node) {
  if (node == 1) return;
  int fa = node >> 1;
  push_down(fa), push_down(node), push_down(node ^ 1);
  v[fa].mn = min(v[node].mn, v[node ^ 1].mn);
  push_up(fa);
}
void build(int l, int r, int node) {
  v[node].l = l, v[node].r = r, v[node].mn = inf;
  if (l == r) {
    v[node].mn = inf, here[l] = node;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, node << 1), build(mid + 1, r, (node << 1) | 1);
}
void Change(int l, int r, int node, long long val) {
  push_down(node);
  if (v[node].l >= l && v[node].r <= r) {
    v[node].lazy = val;
    push_down(node);
    return;
  }
  int mid = (v[node].l + v[node].r) >> 1;
  if (mid >= l) Change(l, r, node << 1, val);
  if (mid < r) Change(l, r, (node << 1) | 1, val);
  push_down(node << 1), push_down((node << 1) | 1);
  v[node].mn = min(v[node << 1].mn, v[(node << 1) | 1].mn);
}
long long dp[Maxn];
long long ask(int l, int r, int node) {
  push_down(node);
  if (v[node].l >= l && v[node].r <= r) return v[node].mn;
  int mid = (v[node].l + v[node].r) >> 1;
  long long tmp = inf;
  if (mid >= l) tmp = ask(l, r, node << 1);
  if (mid < r) tmp = min(tmp, ask(l, r, (node << 1) | 1));
  return tmp;
}
void work(int u, int fa) {
  long long all = 0;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) {
      work(to[i], u);
      all += dp[to[i]];
    }
  for (int i = 0; i < add[u].size(); ++i) {
    int p = pos[add[u][i].id];
    p = here[p];
    v[p].mn = (long long)all + add[u][i].c;
    push_up(p);
  }
  for (int i = 0; i < del[u].size(); ++i) {
    int p = pos[del[u][i].id];
    p = here[p];
    v[p].mn = inf;
    push_up(p);
  }
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) {
      int e = to[i];
      if (in[e] == out[e]) continue;
      if (all <= inf)
        Change(in[e] + 1, out[e], 1, all - dp[e]);
      else
        Change(in[e] + 1, out[e], 1, inf);
    }
  if (in[u] == out[u])
    dp[u] = inf;
  else
    dp[u] = ask(in[u] + 1, out[u], 1);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    AddEdge(u, v), AddEdge(v, u);
  }
  for (int i = 1, u, v, c; i <= m; ++i) {
    scanf("%d%d%d", &u, &v, &c);
    if (u == v) continue;
    add[u].push_back(Farm(i, c));
    del[v].push_back(Farm(i, c));
  }
  dfs(1, 0);
  build(1, m, 1);
  work(1, 0);
  long long ans = 0;
  for (int i = head[1]; i; i = nxt[i]) {
    ans += dp[to[i]];
    if (ans > inf) ans = inf;
  }
  if (ans >= inf)
    puts("-1");
  else
    printf("%lld\n", ans);
  return 0;
}