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 edge {
  int to, next;
} e[300005 * 4];
long long mn[300005 * 4], tg[300005 * 4], f[300005];
int val[300005], ord[300005], L[300005], R[300005];
int head[300005], out[300005], in[300005];
int n, m, tot, T, x, y, l, r;
void add(int x, int y, int *head) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void build(int k, int l, int r) {
  tg[k] = 0;
  mn[k] = 1e9;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(k * 2, l, mid);
  build(k * 2 + 1, mid + 1, r);
}
void change(int k, int l, int r, int x, long long v) {
  if (l == r) {
    mn[k] = v;
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid)
    change(k * 2, l, mid, x, v);
  else
    change(k * 2 + 1, mid + 1, r, x, v);
  mn[k] = min(min(mn[k * 2], mn[k * 2 + 1]) + tg[k], 1000000000000000000ll);
}
void add(int k, int l, int r, int x, int y, long long v) {
  if (x > y) return;
  if (l == x && r == y) {
    tg[k] += v;
    mn[k] += v;
    return;
  }
  int mid = (l + r) / 2;
  if (y <= mid)
    add(k * 2, l, mid, x, y, v);
  else if (x > mid)
    add(k * 2 + 1, mid + 1, r, x, y, v);
  else
    add(k * 2, l, mid, x, mid, v), add(k * 2 + 1, mid + 1, r, mid + 1, y, v);
  mn[k] = min(min(mn[k * 2], mn[k * 2 + 1]) + tg[k], 1000000000000000000ll);
}
long long ask(int k, int l, int r, int x, int y) {
  if (x > y) return 1000000000000000000ll;
  if (l == x && r == y) return mn[k];
  int mid = (l + r) / 2;
  if (y <= mid)
    return min(ask(k * 2, l, mid, x, y) + tg[k], 1000000000000000000ll);
  if (x > mid)
    return min(ask(k * 2 + 1, mid + 1, r, x, y) + tg[k], 1000000000000000000ll);
  return min(
      min(ask(k * 2, l, mid, x, mid), ask(k * 2 + 1, mid + 1, r, mid + 1, y)) +
          tg[k],
      1000000000000000000ll);
}
void dfs(int x, int fa) {
  L[x] = T + 1;
  for (int i = in[x]; i; i = e[i].next) ord[e[i].to] = ++T;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) dfs(e[i].to, x);
  R[x] = T;
}
void solve(int x, int fa) {
  long long ans = 0;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) {
      solve(e[i].to, x);
      ans = min(ans + f[e[i].to], 1000000000000000000ll);
    }
  if (x == 1) {
    f[1] = ans;
    return;
  }
  for (int i = in[x]; i; i = e[i].next)
    change(1, 1, m, ord[e[i].to], ans + val[e[i].to]);
  for (int i = out[x]; i; i = e[i].next)
    change(1, 1, m, ord[e[i].to], 1000000000000000000ll);
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) add(1, 1, m, L[e[i].to], R[e[i].to], ans - f[e[i].to]);
  f[x] = ask(1, 1, m, L[x], R[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    add(x, y, head);
    add(y, x, head);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &val[i]);
    add(l, i, in);
    add(r, i, out);
  }
  dfs(1, 0);
  build(1, 1, m);
  solve(1, 0);
  printf("%I64d", f[1] == 1000000000000000000ll ? -1 : f[1]);
}