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;
template <class T>
inline void init(T& x) {
  x = 0;
  char ch = getchar();
  bool t = 0;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') t = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch - 48);
  if (t) x = -x;
  return;
}
const int N = 3e5 + 10;
const int INF = 1e9;
struct road {
  int s, t, cost;
  road() {}
  road(int _s, int _t, int _cost) { s = _s, t = _t, cost = _cost; }
} R[N];
struct edge {
  int to, next;
} a[N << 1];
int head[N], cnt = 0;
inline void add(int x, int y) {
  a[++cnt] = (edge){y, head[x]};
  head[x] = cnt;
}
int n, m, dep[N], sum[N], fa[N], S[N];
vector<int> U[N];
struct node {
  node *ls, *rs;
  int data, key, tag, dis;
} T[N];
int cur = 0;
node* rt[N];
long long ans = 0;
void dfs(int u) {
  for (int v, i = head[u]; i; i = a[i].next) {
    v = a[i].to;
    if (v == fa[u]) continue;
    dep[v] = dep[u] + 1;
    fa[v] = u;
    dfs(v);
  }
  return;
}
inline void Put(node* A, int x) {
  if (A) {
    A->key += x, A->tag += x;
    return;
  }
}
inline void push_down(node* A) {
  if (!A || !A->tag) return;
  Put(A->ls, A->tag);
  Put(A->rs, A->tag);
  A->tag = 0;
  return;
}
inline node* Merge(node* A, node* B) {
  if (!A) return B;
  if (!B) return A;
  push_down(A), push_down(B);
  if (A->key > B->key) swap(A, B);
  A->rs = Merge(A->rs, B);
  if (((A->ls) ? ((A->ls)->dis) : (-1)) < ((A->rs) ? ((A->rs)->dis) : (-1)))
    swap(A->ls, A->rs);
  A->dis = ((A->rs) ? ((A->rs)->dis) : (-1)) + 1;
  return A;
}
void DFS(int u, int fa) {
  for (int v, i = head[u]; i; i = a[i].next) {
    v = a[i].to;
    if (v == fa) continue;
    DFS(v, u);
    rt[u] = Merge(rt[u], rt[v]);
    S[u] += S[v];
    if (!S[v]) {
      puts("-1");
      exit(0);
    }
  }
  if (u == 1) return;
  while (rt[u] && dep[rt[u]->data] >= dep[u])
    rt[u] = Merge(rt[u]->ls, rt[u]->rs);
  int w = rt[u] ? rt[u]->key : 0;
  ans += w;
  Put(rt[u], -w);
  return;
}
int main() {
  init(n), init(m);
  int u, v, c;
  for (int i = 1; i < n; ++i) {
    init(u), init(v);
    add(u, v), add(v, u);
  }
  dfs(1);
  for (int i = 1; i <= m; ++i) {
    init(u), init(v), init(c);
    if (dep[u] < dep[v]) swap(u, v);
    R[i] = road(u, v, c);
    U[u].push_back(i);
    ++S[u], --S[v];
  }
  for (int i = 1; i <= m; ++i) {
    T[i].data = R[i].t;
    T[i].key = R[i].cost;
    rt[R[i].s] = Merge(rt[R[i].s], &T[i]);
  }
  DFS(1, 0);
  cout << ans << endl;
  return 0;
}