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 MOD = 1000000007;
const int INF = 1000000001;
const long long LINF = 500000000000000LL;
struct MySet {
  struct elem {
    long long val;
    int u, v;
    bool operator<(const elem &other) const {
      return make_tuple(val, u, v) < make_tuple(other.val, other.u, other.v);
    }
  };
  multiset<elem> s;
  long long add = 0;
  map<pair<int, int>, multiset<elem>::iterator> iter;
  void ins(long long val, int u, int v) {
    iter[{u, v}] = s.insert({val - add, u, v});
  }
  void del(int u, int v) { s.erase(iter[{u, v}]); }
  void addToAll(long long amount) { add += amount; }
  multiset<elem> getAll() {
    multiset<elem> res;
    for (auto e : s) {
      e.val += add;
      res.insert(e);
    }
    return res;
  }
  long long best() {
    if (s.empty())
      return LINF;
    else
      return s.begin()->val + add;
  }
  int getSize() { return s.size(); }
};
vector<MySet> sets;
int mergeSets(int i, int j) {
  if (sets[i].getSize() < sets[j].getSize()) {
    swap(i, j);
  }
  for (auto e : sets[j].getAll()) {
    sets[i].ins(e.val, e.u, e.v);
  }
  return i;
}
int dfs(int v, int par, vector<vector<int>> &g, vector<long long> &ans,
        vector<vector<pair<int, int>>> &pathsUp,
        vector<vector<pair<int, int>>> &pathsDown) {
  int id = v;
  vector<pair<int, int>> sons;
  long long ansSum = 0;
  for (int u : g[v])
    if (u != par) {
      sons.push_back({u, dfs(u, v, g, ans, pathsUp, pathsDown)});
      ansSum += ans[u];
    }
  ansSum = min(ansSum, 2 * LINF);
  for (auto p : sons) {
    int u = p.first, sonId = p.second;
    sets[sonId].addToAll(ansSum - ans[u]);
    id = mergeSets(id, sonId);
  }
  for (auto path : pathsUp[v]) {
    sets[id].ins(path.second + ansSum, v, path.first);
  }
  for (auto path : pathsDown[v]) {
    sets[id].del(path.first, v);
  }
  ans[v] = sets[id].best();
  return id;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = (1); i <= (n - 1); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<long long> ans(n, LINF);
  map<pair<int, int>, long long> bestCost;
  vector<vector<pair<int, int>>> pathsUp(n), pathsDown(n);
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    long long c;
    cin >> u >> v >> c;
    u--;
    v--;
    if (u != v) {
      pair<int, int> p = {u, v};
      if (!bestCost.count(p))
        bestCost[p] = c;
      else
        bestCost[p] = min(bestCost[p], c);
    }
  }
  for (auto e : bestCost) {
    int u = e.first.first, v = e.first.second;
    long long cost = e.second;
    pathsUp[u].push_back({v, cost});
    pathsDown[v].push_back({u, cost});
  }
  sets.resize(n);
  dfs(0, -1, g, ans, pathsUp, pathsDown);
  long long answer = 0;
  for (int u : g[0]) {
    answer = min(LINF, answer + ans[u]);
  }
  cout << (answer == LINF ? -1 : answer);
  return 0;
}