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;
struct data {
  int nex, to;
} e[300010 * 2];
int head[300010], edge = 0, L[300010], R[300010], dfn[300010], de = 0, m;
long long b[300010 * 4], lazy[300010 * 4], f[300010], val[300010];
vector<int> s[300010], t[300010];
inline void add(int from, int to) {
  e[++edge].nex = head[from];
  e[edge].to = to;
  head[from] = edge;
}
void dfs1(int x, int fa) {
  L[x] = de + 1;
  for (unsigned int i = 0; i < s[x].size(); i++) dfn[s[x][i]] = ++de;
  for (int i = head[x]; i; i = e[i].nex) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs1(v, x);
  }
  R[x] = de;
}
void Add(int o, int l, int r, int u, int v, long long w) {
  if (v < u) return;
  if (l > v || r < u) return;
  if (l >= u && r <= v) {
    b[o] += w, lazy[o] += w;
    return;
  }
  int mid = (l + r) >> 1;
  if (v <= mid)
    Add(o * 2, l, mid, u, v, w);
  else if (u > mid)
    Add(o * 2 + 1, mid + 1, r, u, v, w);
  else
    Add(o * 2, l, mid, u, mid, w), Add(o * 2 + 1, mid + 1, r, mid + 1, v, w);
  b[o] = min(b[o * 2], b[o * 2 + 1]);
  if (b[o] > 100000000000000 * 10) b[o] = 100000000000000 * 10;
}
inline void down(int o) {
  long long x = lazy[o];
  lazy[o] = 0;
  if (!x) return;
  lazy[o * 2] += x, lazy[o * 2 + 1] += x;
  b[o * 2] += x, b[o * 2 + 1] += x;
}
void change(int o, int l, int r, int p, long long w) {
  if (l != r) down(o);
  if (l == r) {
    b[o] = w;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    change(o * 2, l, mid, p, w);
  else
    change(o * 2 + 1, mid + 1, r, p, w);
  b[o] = min(b[o * 2], b[o * 2 + 1]);
  if (b[o] > 100000000000000 * 10) b[o] = 100000000000000 * 10;
}
long long query(int o, int l, int r, int u, int v) {
  if (v < u) return 100000000000000;
  if (l != r) down(o);
  if (l > v || r < u) return 100000000000000;
  if (l >= u && r <= v) return b[o];
  int mid = (l + r) >> 1;
  if (v <= mid)
    return query(o * 2, l, mid, u, v);
  else if (u > mid)
    return query(o * 2 + 1, mid + 1, r, u, v);
  else
    return min(query(o * 2, l, mid, u, mid),
               query(o * 2 + 1, mid + 1, r, mid + 1, v));
}
void dfs(int x, int fa) {
  long long sum = 0;
  for (int i = head[x]; i; i = e[i].nex) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, x);
    sum += f[v];
    if (sum > 100000000000000 * 10) sum = 100000000000000 * 10;
  }
  for (unsigned int i = 0; i < s[x].size(); i++)
    change(1, 1, m, dfn[s[x][i]], sum + val[s[x][i]]);
  for (unsigned int i = 0; i < t[x].size(); i++)
    change(1, 1, m, dfn[t[x][i]], 100000000000000);
  if (x == 1) {
    if (sum >= 100000000000000) sum = -1;
    printf("%I64d", sum), exit(0);
  }
  for (int i = head[x]; i; i = e[i].nex) {
    int v = e[i].to;
    if (v == fa) continue;
    Add(1, 1, m, L[v], R[v], sum - f[v]);
  }
  f[x] = query(1, 1, m, L[x], R[x]);
}
int main() {
  int n, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 4 * m; i++) b[i] = 100000000000000;
  for (int i = 1; i < n; i++) scanf("%d%d", &x, &y), add(x, y), add(y, x);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%I64d", &x, &y, &val[i]), s[x].push_back(i), t[y].push_back(i);
  dfs1(1, 0);
  dfs(1, 0);
  return 0;
}