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>
struct edge {
  int b, ne;
} da[2 * 300010];
int head[300010], TOT = 1;
void insert(int a, int b) {
  da[++TOT] = (edge){b, head[a]};
  head[a] = TOT;
}
int n, L[300010], R[300010], Tclock = 0, id[300010], m;
struct project {
  int u, v, w;
} no[300010];
long long f[300010];
std::vector<int> st[300010], en[300010];
namespace Judge {
int du[300010];
void dfs(int x, int fa) {
  for (int t = head[x]; t; t = da[t].ne)
    if (da[t].b != fa) dfs(da[t].b, x), du[x] += du[da[t].b];
}
bool judge() {
  dfs(1, 0);
  for (int i = 2; i <= n; i++)
    if (!du[i]) return false;
  return true;
}
}  // namespace Judge
void dfs(int x, int fa) {
  L[x] = Tclock + 1;
  for (int i = 0; i < st[x].size(); i++) id[st[x][i]] = ++Tclock;
  for (int t = head[x]; t; t = da[t].ne)
    if (da[t].b != fa) dfs(da[t].b, x);
  R[x] = Tclock;
}
namespace seg {
int ls[2 * 300010], rs[2 * 300010], TOT = 1;
long long Min[2 * 300010], tag[2 * 300010];
void maketree(int rt, int l, int r) {
  Min[rt] = tag[rt] = 0;
  if (l == r) return;
  ls[rt] = ++TOT;
  rs[rt] = ++TOT;
  int mid = (l + r) >> 1;
  maketree(ls[rt], l, mid);
  maketree(rs[rt], mid + 1, r);
}
void pushdown(int rt) {
  if (tag[rt]) {
    tag[ls[rt]] += tag[rt];
    tag[rs[rt]] += tag[rt];
    Min[ls[rt]] += tag[rt];
    Min[rs[rt]] += tag[rt];
    tag[rt] = 0;
  }
}
void add(int rt, int l, int r, int a, int b, long long c) {
  if (a <= l && r <= b) {
    tag[rt] += c;
    Min[rt] += c;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(rt);
  if (a <= mid) add(ls[rt], l, mid, a, b, c);
  if (mid < b) add(rs[rt], mid + 1, r, a, b, c);
  Min[rt] = std::min(Min[ls[rt]], Min[rs[rt]]);
}
long long query(int rt, int l, int r, int a, int b) {
  if (a <= l && r <= b) return Min[rt];
  pushdown(rt);
  int mid = (l + r) >> 1;
  long long ans = 1000000000000000LL;
  if (a <= mid) ans = std::min(ans, query(ls[rt], l, mid, a, b));
  if (mid < b) ans = std::min(ans, query(rs[rt], mid + 1, r, a, b));
  return ans;
}
}  // namespace seg
void dp(int x, int fa) {
  long long all = 0;
  for (int t = head[x]; t; t = da[t].ne)
    if (da[t].b != fa) {
      dp(da[t].b, x);
      all += f[da[t].b];
    }
  if (x == 1) {
    f[x] = all;
    return;
  }
  for (int i = 0; i < st[x].size(); i++)
    seg::add(1, 1, m, id[st[x][i]], id[st[x][i]], all + no[st[x][i]].w);
  for (int i = 0; i < en[x].size(); i++)
    seg::add(1, 1, m, id[en[x][i]], id[en[x][i]], 1000000000000000LL);
  for (int t = head[x]; t; t = da[t].ne)
    if (da[t].b != fa)
      seg::add(1, 1, m, L[da[t].b], R[da[t].b], all - f[da[t].b]);
  f[x] = seg::query(1, 1, m, L[x], R[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    insert(u, v);
    insert(v, u);
  }
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    no[i] = (project){u, v, w};
    Judge::du[u]++;
    Judge::du[v]--;
    st[u].push_back(i);
    en[v].push_back(i);
  }
  if (!Judge::judge()) {
    printf("-1");
    return 0;
  }
  Tclock = 0;
  dfs(1, 0);
  seg::maketree(1, 1, m);
  dp(1, 0);
  printf("%I64d", f[1]);
  return 0;
}