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 pp {
  int lc, rc;
  long long k, mark;
} p[600010];
int root, pl;
struct node {
  int y, next;
} a[600010];
int first[300010], len;
vector<int> A[300010], K[300010], B[300010];
int L[300010], R[300010], id;
int d[300010], m;
long long f[300010];
int ok = 1;
long long _Min(long long x, long long y) { return x < y ? x : y; }
void ins(int x, int y) {
  a[++len].y = y;
  a[len].next = first[x];
  first[x] = len;
}
void build(int &x, int l, int r, int ll, int rr, long long k) {
  if (!x) x = ++pl;
  if (l == ll && r == rr) {
    p[x].mark += k;
    p[x].k += k;
    return;
  }
  int mid = (l + r) >> 1;
  if (rr <= mid)
    build(p[x].lc, l, mid, ll, rr, k);
  else if (ll > mid)
    build(p[x].rc, mid + 1, r, ll, rr, k);
  else {
    build(p[x].lc, l, mid, ll, mid, k);
    build(p[x].rc, mid + 1, r, mid + 1, rr, k);
  }
  p[x].k = _Min(p[p[x].lc].k, p[p[x].rc].k) + p[x].mark;
}
long long query(int x, int l, int r, int ll, int rr) {
  if (!x) return 0;
  if (l == ll && r == rr) return p[x].k;
  int mid = (l + r) >> 1;
  if (rr <= mid) return query(p[x].lc, l, mid, ll, rr) + p[x].mark;
  if (ll > mid) return query(p[x].rc, mid + 1, r, ll, rr) + p[x].mark;
  return _Min(query(p[x].lc, l, mid, ll, mid),
              query(p[x].rc, mid + 1, r, mid + 1, rr)) +
         p[x].mark;
}
void dfs(int x, int fa) {
  int k, y;
  d[x] = d[fa] + 1;
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    if (y == fa) continue;
    dfs(y, x);
  }
}
void DFS(int x, int fa) {
  int k, y;
  long long s = 0;
  L[x] = id + 1;
  for (int i = 0; i < A[x].size(); i++) {
    id++;
    build(root, 1, m, id, id, K[x][i]);
    if (A[x][i] != 1) B[A[x][i]].push_back(id);
  }
  R[x] = id;
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    if (y == fa) continue;
    DFS(y, x);
    R[x] = R[y];
    s += f[y];
  }
  if (L[x] > R[x]) {
    ok = 0;
    return;
  }
  build(root, 1, m, L[x], R[x], s);
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    if (y == fa) continue;
    if (L[y] <= R[y]) build(root, 1, m, L[y], R[y], -f[y]);
  }
  for (int i = 0; i < B[x].size(); i++)
    build(root, 1, m, B[x][i], B[x][i], (long long)1000000000 * 1000000);
  f[x] = query(root, 1, m, L[x], R[x]);
  if (f[x] >= (long long)1000000000 * 1000000) {
    ok = 0;
    f[x] = 0;
  }
}
int main() {
  int n, i, j, x, y, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
  dfs(1, 0);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &k);
    if (d[x] < d[y]) {
      int t = x;
      x = y;
      y = t;
    }
    if (x == y) continue;
    A[x].push_back(y);
    K[x].push_back(k);
  }
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  DFS(1, 0);
  if (!ok)
    printf("-1\n");
  else
    printf("%I64d\n", f[1]);
  return 0;
}