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 + 5;
int n, m;
int dep[maxn];
long long ans = 0;
vector<int> g[maxn];
vector<pair<int, int> > qry[maxn];
class Node {
 public:
  long long delta;
  set<pair<int, long long>, greater<pair<int, long long> > > s1;
  set<pair<long long, int> > s2;
  inline void insert(pair<int, long long> p) {
    s1.insert(make_pair(p.first, p.second - delta));
    s2.insert(make_pair(p.second - delta, p.first));
    return;
  }
  inline void merge(Node &oth) {
    if (s1.size() < oth.s1.size()) swap(*this, oth);
    for (set<pair<int, long long> >::iterator it = oth.s1.begin();
         it != oth.s1.end(); ++it)
      s1.insert(make_pair(it->first, it->second + oth.delta - delta));
    for (set<pair<long long, int> >::iterator it = oth.s2.begin();
         it != oth.s2.end(); ++it)
      s2.insert(make_pair(it->first + oth.delta - delta, it->second));
    return;
  }
  inline void modify(int d) {
    while (s1.size() && (s1.begin()->first) > d) {
      pair<int, long long> p = *s1.begin();
      s2.erase(make_pair(p.second, p.first));
      s1.erase(p);
    }
    if (!s2.size()) {
      printf("%d\n", -1);
      exit(0);
    }
    pair<long long, int> p = *s2.begin();
    ans += p.first + delta;
    delta -= p.first + delta;
    return;
  }
};
inline Node dfs(int u, int p) {
  if (~p) dep[u] = dep[p] + 1;
  Node ret;
  for (int i = (0); i < (g[u].size()); ++i) {
    int v = g[u][i];
    if (v == p) continue;
    Node res = dfs(v, u);
    res.modify(dep[u]);
    ret.merge(res);
  }
  for (int i = (0); i < (qry[u].size()); ++i) {
    int v = qry[u][i].first, w = qry[u][i].second;
    ret.insert(make_pair(dep[v], w));
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (n); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = (0); i < (m); ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    --u;
    --v;
    qry[u].push_back(make_pair(v, w));
  }
  dfs(0, -1);
  printf("%lld\n", ans);
  return 0;
}