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 <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 300000;
int n, m;
vector<int> adj[maxn + 5];
int dep[maxn + 5], fa[maxn + 5];
void pre_dfs(int first) {
  for (auto second : adj[first]) {
    if (second == fa[first]) continue;
    fa[second] = first, dep[second] = dep[first] + 1, pre_dfs(second);
  }
}
set<pair<int, int> > all[maxn + 5];
int delta[maxn + 5];
long long ans = 0;
inline void merge(int u, int v) {
  if ((int((all[u]).size())) > (int((all[v]).size())))
    swap(all[u], all[v]), swap(delta[u], delta[v]);
  int d = delta[u] - delta[v];
  for (auto first : all[u])
    all[v].insert(make_pair(first.first + d, first.second));
  all[u].clear();
}
int dfs(int first) {
  int id = first;
  for (auto second : adj[first])
    if (second != fa[first]) {
      int tmp = dfs(second);
      if (dep[tmp] < dep[id]) id = tmp;
    }
  if (first == 0) return first;
  if (id == first) {
    while (!all[first].empty() && dep[all[first].begin()->second] >= dep[first])
      all[first].erase(all[first].begin());
    if (all[first].empty()) {
      puts("-1");
      exit(0);
    }
    auto cur = *all[first].begin();
    all[first].erase(all[first].begin());
    ans += delta[first] + cur.first;
    delta[first] = -cur.first;
    merge(first, cur.second);
    id = cur.second;
  } else
    merge(first, id);
  return id;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0), _end_ = (n - 1); i < _end_; ++i) {
    int u, v;
    scanf("%d%d", &u, &v), --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  fa[0] = -1;
  pre_dfs(0);
  for (int i = (0), _end_ = (m); i < _end_; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w), --u, --v;
    if (u != v) all[u].insert(make_pair(w, v));
  }
  dfs(0);
  printf("%I64d\n", ans);
  return 0;
}