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 v, nxt;
} e[1000005];
int n, m, rt[300005];
long long sum[9000005], lazy[9000005], f[300005];
int ls[9000005], rs[9000005], h[300005], t, d[300005], cnt;
void add(int u, int v) {
  e[++t].v = v;
  e[t].nxt = h[u];
  h[u] = t;
}
void pushup(int x) { sum[x] = min(sum[ls[x]], sum[rs[x]]); }
void col(int x, long long v) {
  lazy[x] += v;
  sum[x] += v;
}
void pushdown(int x) {
  if (lazy[x]) {
    if (ls[x]) col(ls[x], lazy[x]);
    if (rs[x]) col(rs[x], lazy[x]);
    lazy[x] = 0;
  }
}
void modify(int x, int l, int r, int ql, int qr, long long v) {
  if (l > qr || r < ql || !x) return;
  if (ql <= l && r <= qr) {
    col(x, v);
    return;
  }
  int mid = (l + r) / 2;
  pushdown(x);
  modify(ls[x], l, mid, ql, qr, v);
  modify(rs[x], mid + 1, r, ql, qr, v);
  pushup(x);
}
int modifyp(int x, int l, int r, int qx, long long v) {
  if (l > qx || r < qx) return x;
  if (!x) x = ++cnt, sum[x] = 1e18;
  if (l == r) {
    sum[x] = min(sum[x], (long long)v);
    return x;
  }
  pushdown(x);
  int mid = (l + r) / 2;
  ls[x] = modifyp(ls[x], l, mid, qx, v);
  rs[x] = modifyp(rs[x], mid + 1, r, qx, v);
  pushup(x);
  return x;
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  pushdown(x);
  pushdown(y);
  sum[x] = min(sum[x], sum[y]);
  ls[x] = merge(ls[x], ls[y]);
  rs[x] = merge(rs[x], rs[y]);
  return x;
}
long long query(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql || !x) return 1e18;
  if (ql <= l && r <= qr) return sum[x];
  int mid = (l + r) / 2;
  pushdown(x);
  return min(query(ls[x], l, mid, ql, qr), query(rs[x], mid + 1, r, ql, qr));
}
void dfs(int u, int fa, int dep) {
  d[u] = dep;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u, dep + 1);
  }
}
void dfs2(int u, int fa) {
  long long ssum = 0;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs2(v, u);
    ssum += f[v];
  }
  modify(rt[u], 1, n, 1, n, ssum);
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    modify(rt[v], 1, n, 1, n, ssum - f[v]);
    rt[u] = merge(rt[u], rt[v]);
  }
  f[u] = query(rt[u], 1, n, 1, u == 1 ? d[u] : d[u] - 1);
  if (f[u] == 1e18) {
    printf("-1\n");
    exit(0);
  }
}
int main() {
  sum[0] = 1e18;
  scanf("%d%d", &n, &m);
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1, 0, 1);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    rt[u] = modifyp(rt[u], 1, n, d[v], w);
  }
  dfs2(1, 0);
  printf("%lld\n", f[1]);
  return 0;
}