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;
const int maxn = 3e5 + 10;
const long long inf = 1000000000000000ll;
struct node {
  int l, r;
  long long x, lazy;
} t[maxn << 2];
int n, m, tot, v, u, indexx;
int in[maxn], out[maxn];
struct edge {
  int v, next;
} e[maxn << 1];
int h[maxn], num, pos[maxn], c[maxn];
vector<int> a[maxn], d[maxn];
long long f[maxn];
bool flag = false;
inline long long min(long long x, long long y) { return x < y ? x : y; }
void build_edge(int u, int v) {
  num++;
  e[num].v = v;
  e[num].next = h[u];
  h[u] = num;
}
void build(int p, int l, int r) {
  int mid = (l + r) >> 1;
  t[p].x = inf;
  if (l == r) return;
  t[p].l = ++tot;
  t[p].r = ++tot;
  build(t[p].l, l, mid);
  build(t[p].r, mid + 1, r);
}
inline void update(int p, long long lazy) {
  t[p].x += lazy;
  t[p].lazy += lazy;
}
void change(int p, int l, int r, int pos, long long c) {
  int mid = (l + r) >> 1;
  if (l == r) {
    t[p].x = c;
    return;
  }
  int ls = t[p].l;
  int rs = t[p].r;
  if (t[p].lazy) {
    update(ls, t[p].lazy);
    update(rs, t[p].lazy);
    t[p].lazy = 0;
  }
  if (pos <= mid)
    change(ls, l, mid, pos, c);
  else if (pos > mid)
    change(rs, mid + 1, r, pos, c);
  t[p].x = min(t[ls].x, t[rs].x);
}
void add(int p, int l, int r, int L, int R, long long c) {
  int mid = (l + r) >> 1;
  if (l == L && R == r) {
    t[p].x += c;
    t[p].lazy += c;
    return;
  }
  int ls = t[p].l;
  int rs = t[p].r;
  if (t[p].lazy) {
    update(ls, t[p].lazy);
    update(rs, t[p].lazy);
    t[p].lazy = 0;
  }
  if (R <= mid)
    add(ls, l, mid, L, R, c);
  else if (L > mid)
    add(rs, mid + 1, r, L, R, c);
  else
    add(ls, l, mid, L, mid, c), add(rs, mid + 1, r, mid + 1, R, c);
  t[p].x = min(t[ls].x, t[rs].x);
}
long long getans(int p, int l, int r, int L, int R) {
  int mid = (l + r) >> 1;
  if (l == L && r == R) return t[p].x;
  int ls = t[p].l;
  int rs = t[p].r;
  if (t[p].lazy) {
    update(ls, t[p].lazy);
    update(rs, t[p].lazy);
    t[p].lazy = 0;
  }
  if (R <= mid)
    return getans(ls, l, mid, L, R);
  else if (L > mid)
    return getans(rs, mid + 1, r, L, R);
  return min(getans(ls, l, mid, L, mid), getans(rs, mid + 1, r, mid + 1, R));
}
void dfs(int x, int fa) {
  in[x] = ++indexx;
  for (int i = 0; i < (int)a[x].size(); i++) pos[a[x][i]] = ++indexx;
  for (int i = h[x]; i; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, x);
  }
  out[x] = indexx;
}
void dp(int x, int fa) {
  long long res = 0;
  int v;
  for (int i = h[x]; i; i = e[i].next) {
    v = e[i].v;
    if (fa == v) continue;
    dp(v, x);
    if (f[v] >= inf) flag = true;
    res += f[v];
  }
  if (x == 1) {
    f[1] = res;
    return;
  }
  for (int i = 0; i < (int)a[x].size(); i++) {
    v = a[x][i];
    change(0, 1, indexx, pos[v], res + c[v]);
  }
  for (int i = 0; i < (int)d[x].size(); i++) {
    v = d[x][i];
    change(0, 1, indexx, pos[v], inf);
  }
  for (int i = h[x]; i; i = e[i].next) {
    v = e[i].v;
    if (fa == v) continue;
    add(0, 1, indexx, in[v], out[v], res - f[v]);
  }
  f[x] = getans(0, 1, indexx, in[x], out[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    build_edge(u, v);
    build_edge(v, u);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &c[i]);
    a[u].push_back(i);
    d[v].push_back(i);
  }
  dfs(1, 0);
  build(0, 1, indexx);
  for (int i = 1; i <= n; i++) f[i] = inf;
  dp(1, 0);
  if (flag)
    printf("-1\n");
  else
    printf("%I64d\n", f[1]);
  return 0;
}