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 N = 3e5 + 10;
inline long long rd() {
  long long x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N << 1], nt[N << 1], hd[N], tot = 1;
inline void add(int x, int y) {
  ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot;
  ++tot, to[tot] = x, nt[tot] = hd[y], hd[y] = tot;
}
struct chn {
  int to[N], nt[N], hd[N], tot;
  void add(int x, int y) { ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot; }
} l1, l2;
struct node {
  long long x;
  int i;
  bool operator<(const node &bb) const { return x > bb.x; }
};
set<int>::iterator it;
int w[N];
struct HEAP {
  priority_queue<node> q1;
  set<int> q2;
  long long dt;
  void del() {
    while (q2.size() && q2.count(q1.top().i))
      q2.erase(q2.find(q1.top().i)), q1.pop();
  }
  void push(int i) { q1.push((node){w[i] - dt, i}); }
  void pop(int i) { q2.insert(i); }
  int size() {
    del();
    return q1.size() - q2.size();
  }
  int top() {
    del();
    return q1.empty() ? 1 << 30 : q1.top().x + dt;
  }
} hp[N];
int n, m, fa[N], de[N], s[N], ts, ff[N];
long long ans;
inline int findf(int x) { return ff[x] == x ? x : ff[x] = findf(ff[x]); }
void merge(int x, int y) {
  x = findf(x), y = findf(y);
  if (hp[x].size() < hp[y].size()) swap(x, y);
  while (!hp[y].q1.empty())
    hp[x].q1.push(
        (node){hp[y].q1.top().x + hp[y].dt - hp[x].dt, hp[y].q1.top().i}),
        hp[y].q1.pop();
  for (it = hp[y].q2.begin(); it != hp[y].q2.end(); ++it) hp[x].pop(*it);
  hp[y].q2.clear();
  ff[y] = x;
}
int main() {
  n = rd(), m = rd();
  for (int i = 1; i < n; ++i) add(rd(), rd());
  de[1] = 1;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    s[++ts] = x;
    for (int i = hd[x]; i; i = nt[i]) {
      int y = to[i];
      if (y == fa[x]) continue;
      fa[y] = x, de[y] = de[x] + 1, q.push(y);
    }
  }
  for (int i = 1; i <= m; ++i) {
    int x = rd(), y = rd();
    w[i] = rd();
    l1.add(x, i), l2.add(y, i);
  }
  for (int i = 1; i <= n; ++i) ff[i] = i;
  while (ts > 1) {
    int x = s[ts--], xx = findf(x);
    for (int i = l1.hd[x]; i; i = l1.nt[i]) hp[xx].push(l1.to[i]);
    for (int i = l2.hd[x]; i; i = l2.nt[i]) hp[xx].pop(l2.to[i]);
    if (hp[xx].size() == 0) {
      puts("-1");
      exit(0);
    }
    ans += hp[xx].top(), hp[xx].dt -= hp[xx].top();
    if (ts) merge(x, fa[x]);
  }
  cout << ans << endl;
  return 0;
}