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 = 4 * 100 * 1000;
const long long INF = (long long)1000 * 1000 * 1000 * 1000 * 1000;
vector<int> g[MAXN];
vector<pair<int, long long> > who[MAXN];
struct myset {
  map<int, long long> s;
  set<pair<int, long long> > mi;
  long long pl;
  myset() : pl(0){};
  void add(pair<int, long long> b) {
    b.second -= pl;
    if (s.count(b.first) == 0) {
      s[b.first] = b.second;
      mi.insert(make_pair(b.second, b.first));
    } else {
      mi.erase(make_pair(s[b.first], b.first));
      s[b.first] = min(b.second, s[b.first]);
      mi.insert(make_pair(s[b.first], b.first));
    }
  }
  void relax(int h) {
    while (!s.empty()) {
      auto it = s.end();
      it--;
      if (it->first > h) {
        mi.erase(make_pair(it->second, it->first));
        s.erase(it);
      } else {
        break;
      }
    }
  }
  long long get_mi() {
    if (s.empty()) {
      return INF;
    }
    return mi.begin()->first + pl;
  }
};
typedef myset *pset;
pset merge(pset &a, pset &b) {
  if (((int)(a->s.size())) > ((int)(b->s.size()))) {
    swap(a, b);
  }
  for (auto it : a->s) {
    it.second += a->pl;
    it.second = min(it.second, INF);
    b->add(it);
  }
  return b;
}
int h[MAXN], was[MAXN];
void find_h(int v, int _h) {
  if (was[v]) {
    return;
  }
  was[v] = 1;
  h[v] = _h;
  for (int u : g[v]) {
    find_h(u, _h + 1);
  }
}
pset dfs(int v) {
  was[v] = 1;
  pset ans = new myset;
  vector<pset> cur;
  vector<long long> cost;
  long long sum = 0;
  for (int u : g[v]) {
    if (!was[u]) {
      cur.push_back(dfs(u));
      cur.back()->relax(h[v]);
      cost.push_back(cur.back()->get_mi());
      sum += cost.back();
      sum = min(sum, INF);
    }
  }
  for (pair<int, int> buf : who[v]) {
    ans->add(buf);
  }
  ans->pl += sum;
  for (int i = 0; i < ((int)(cur.size())); i++) {
    cur[i]->pl += sum - cost[i];
    ans = merge(ans, cur[i]);
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%i %i", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(was, 0, sizeof was);
  find_h(0, 0);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    scanf("%i %i %i", &u, &v, &c);
    u--;
    v--;
    assert(h[u] >= h[v]);
    who[u].push_back(make_pair(h[v], c));
  }
  who[0].push_back(make_pair(0, 0));
  for (int i = 0; i < n; i++) {
    sort(who[i].begin(), who[i].end());
    long long mi = INF;
    for (int j = 0; j < ((int)(who[i].size())); j++) {
      mi = min(mi, who[i][j].second);
      who[i][j].second = mi;
    }
  }
  memset(was, 0, sizeof was);
  pset ans = dfs(0);
  if (ans->get_mi() >= INF) {
    cout << -1 << endl;
  } else {
    cout << (ans->get_mi()) << endl;
  }
  return 0;
}