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;
struct node {
  int d1;
  long long d2;
  set<pair<int, long long> > *ss;
  node() {
    d1 = d2 = 0;
    ss = new set<pair<int, long long> >();
  }
  void add(pair<int, long long> u) {
    u.first -= d1;
    u.second -= d2;
    auto it = ss->lower_bound(make_pair(u.first, -d2));
    if (it != ss->end() && it->second <= u.second) return;
    while (it != ss->end() && it->first == u.first) {
      auto it2 = it;
      it2++;
      ss->erase(it);
      it = it2;
    }
    it = ss->insert(u).first;
    if (it != ss->begin()) {
      --it;
      while (it->second >= u.second) {
        if (it == ss->begin()) {
          ss->erase(it);
          break;
        } else {
          auto it2 = it;
          --it2;
          ss->erase(it);
          it = it2;
        }
      }
    }
  }
};
node merge(node a, node b) {
  if (a.ss->size() < b.ss->size()) swap(a, b);
  if (b.ss->size() == 0) return a;
  long long ad2 = b.ss->begin()->second + b.d2;
  long long bd2 = a.ss->begin()->second + a.d2;
  a.d2 += ad2;
  b.d2 += bd2;
  for (pair<int, long long> u : *b.ss)
    a.add(make_pair(u.first + b.d1, u.second + b.d2));
  return a;
}
void fin() {
  cout << -1 << "\n";
  exit(0);
}
const int MAXN = 310000;
int was[MAXN];
vector<int> eds[MAXN];
vector<pair<int, long long> > go[MAXN];
int h[MAXN];
int n, m;
node dfs(int v) {
  was[v] = 1;
  node xx;
  for (int u : eds[v]) {
    if (was[u]) continue;
    node go = dfs(u);
    --go.d1;
    while (go.ss->size() && go.ss->begin()->first + go.d1 < 0)
      go.ss->erase(go.ss->begin());
    if (go.ss->empty()) fin();
    xx = merge(xx, go);
  }
  long long mn = 0;
  if (!xx.ss->empty()) mn = xx.ss->begin()->second + xx.d2;
  for (int i = 0; i < (int)go[v].size(); ++i)
    xx.add(make_pair(go[v][i].first, go[v][i].second + mn));
  return xx;
}
void dfsh(int v) {
  was[v] = 1;
  for (int u : eds[v]) {
    if (!was[u]) {
      h[u] = h[v] + 1;
      dfsh(u);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    eds[a].push_back(b);
    eds[b].push_back(a);
  }
  h[0] = 0;
  dfsh(0);
  memset(was, 0, sizeof(was));
  for (int i = 0; i < m; ++i) {
    int u, v;
    long long c;
    scanf("%d%d%lld", &u, &v, &c);
    --v;
    --u;
    go[u].push_back(make_pair(h[u] - h[v], c));
  }
  node ans = dfs(0);
  cout << ans.ss->begin()->second + ans.d2 << "\n";
  return 0;
}