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>
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
void update(set<pair<int, long long>> *st, long long base, int d,
            long long cost) {
  auto po = st->lower_bound({d + 1, -1ll});
  if (po != st->begin()) {
    po--;
    if (po->second + base <= cost) return;
  }
  po = st->lower_bound({d, -1ll});
  while (po != st->end() && po->second + base >= cost) po = st->erase(po);
  st->insert({d, cost - base});
}
int n, m;
vector<int> node[323456];
vector<pair<int, int>> worker[323456];
long long ans;
int depth[323456];
bool ok;
set<pair<int, long long>> *dfs(int u, int f, int dep,
                               set<pair<int, long long>> *st, long long &base) {
  depth[u] = dep;
  st->insert({depth[u], 0ll});
  base = 0;
  for (auto it : worker[u]) {
    assert(depth[it.first] != -1);
    update(st, base, depth[it.first], it.second);
  }
  for (int v : node[u])
    if (v != f) {
      set<pair<int, long long>> *tmp = new set<pair<int, long long>>;
      long long tb = 0;
      tmp = dfs(v, u, dep + 1, tmp, tb);
      long long t1 = tmp->size() == 0 ? tb : tmp->rbegin()->second + tb;
      long long t2 = st->size() == 0 ? base : st->rbegin()->second + base;
      base += t1;
      tb += t2;
      if (tmp->size() == 0) {
        ok = false;
      }
      if (!ok) return tmp;
      if (st->size() < tmp->size()) {
        swap(st, tmp);
        swap(base, tb);
      }
      for (auto it : *tmp) {
        update(st, base, it.first, it.second + tb);
      }
    }
  while (st->size() != 0 && st->rbegin()->first >= depth[u]) {
    if (u == 0) ans = st->rbegin()->second + base;
    st->erase(--st->end());
  }
  return st;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < int(n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  for (int i = 0; i < int(m); ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    worker[u].push_back({v, c});
  }
  set<pair<int, long long>> *st = new set<pair<int, long long>>;
  long long base = 0;
  ok = true;
  dfs(0, -1, 0, st, base);
  if (!ok) ans = -1;
  cout << ans << endl;
  return 0;
}