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;
long long int powm(long long int a, int b, int n) {
  long long int rm = 1;
  while (b) {
    if (b % 2) {
      rm = (rm * a) % n;
    }
    a = (a * a) % n;
    b /= 2;
  }
  return rm;
}
long long int inf = 1e15L;
set<pair<long long int, int> > myset[int(3e5 + 1000)];
vector<int> E[int(3e5 + 1000)], Up[int(3e5 + 1000)], Down[int(3e5 + 1000)];
int Uidx[int(3e5 + 1000)];
long long int Cost[int(3e5 + 1000)] = {0}, Extra[int(3e5 + 1000)] = {0};
int L[int(3e5 + 1000)], x[int(3e5 + 1000)], y[int(3e5 + 1000)],
    c[int(3e5 + 1000)], P[int(3e5 + 1000)], set_size[int(3e5 + 1000)] = {0};
bool deactivate[int(3e5 + 1000)] = {false};
void dfs(int node, int root, int level) {
  L[node] = level;
  int idx = -1;
  for (auto cld : E[node]) {
    idx++;
    if (cld != root) {
      dfs(cld, node, level + 1);
    } else
      Uidx[node] = idx;
  }
}
int merge(int u, int v) {
  int add_ext = Extra[v] - Extra[u];
  while (!myset[v].empty()) {
    pair<long long int, int> val = *myset[v].begin();
    myset[v].erase(val);
    set_size[v]--;
    if (deactivate[val.second]) continue;
    val.first += add_ext;
    myset[u].insert(val);
    set_size[u]++;
  }
}
void go(int node, int root) {
  int sz = E[node].size();
  vector<long long int> arr(sz + 1);
  long long int tot = 0;
  for (int i = 0; i < sz; i++) {
    int cld = E[node][i];
    if (cld == root) continue;
    go(cld, node);
    int k = P[cld];
    pair<long long int, int> val = make_pair(inf, -1);
    while (!myset[k].empty()) {
      val = *myset[k].begin();
      if (!deactivate[val.second]) break;
      myset[k].erase(val);
      set_size[k]--;
    }
    if (val.first < inf)
      arr[i] = min(val.first + Extra[k], inf);
    else
      arr[i] = inf;
    tot = min(tot + arr[i], inf);
  }
  Cost[node] = tot;
  int prev_set_sz = -1, mx_idx = -1;
  for (int i = 0; i < sz; ++i) {
    int cld = E[node][i];
    if (cld == root) continue;
    if (set_size[P[cld]] > prev_set_sz) {
      prev_set_sz = set_size[P[cld]];
      mx_idx = i;
    }
  }
  int kf = (mx_idx == -1 ? node : P[E[node][mx_idx]]);
  if (tot >= inf) return;
  for (int i = 0; i < sz; ++i) {
    int cld = E[node][i];
    if (cld == root) continue;
    Extra[P[cld]] = min(Extra[P[cld]] + tot - arr[i], inf);
  }
  for (int i = 0; i < sz; ++i) {
    int cld = E[node][i];
    if (cld == root || i == mx_idx) continue;
    merge(kf, P[cld]);
  }
  pair<long long int, int> val;
  for (auto id : Up[node]) {
    myset[kf].insert(make_pair(min(tot + c[id] - Extra[kf], inf), x[id]));
    set_size[kf]++;
  }
  P[node] = kf;
  deactivate[node] = true;
}
int main() {
  int n, m, u, v;
  scanf("%d", &n);
  ;
  scanf("%d", &m);
  ;
  for (int i = int(1); i <= (int)n - 1; i++) {
    cin >> u >> v;
    E[v].push_back(u);
    E[u].push_back(v);
  }
  dfs(1, 0, 1);
  for (int i = int(1); i <= (int)m; i++) {
    cin >> x[i] >> y[i] >> c[i];
    if (x[i] == y[i]) continue;
    if (L[x[i]] > L[y[i]]) swap(x[i], y[i]);
    Down[x[i]].push_back(i);
    Up[y[i]].push_back(i);
  }
  go(1, 0);
  if (Cost[1] >= inf) Cost[1] = -1;
  cout << Cost[1] << endl;
  return 0;
}