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;
template <typename T>
inline bool smin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool smax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const long long N = (long long)3e5 + 10, inf = (long long)2e14;
long long n, m, st[N], ft[N], tim, dp[N], shuru[N], payan[N], ans[N];
vector<long long> adj[N], rem[N], add[N];
struct option {
  long long u, v, c;
} b[N];
struct node {
  long long mn, lz;
  node() { mn = lz = 0; }
} seg[N << 2];
struct segtree {
  long long mn[N << 2], ed = 0, a[N], rev[N];
  segtree() {
    memset(a, 0, sizeof a);
    memset(rev, 0, sizeof rev);
    fill_n(mn, N << 2, inf);
  }
  void add_option(long long x) {
    rev[x] = ed;
    a[ed++] = b[x].c;
  }
  void change(long long pos, long long val, long long id = 1, long long l = 0,
              long long r = N) {
    if (r - l < 2) {
      mn[id] = val;
      return;
    }
    long long mid = (r + l) >> 1, lc = id << 1, rc = lc | 1;
    if (pos < mid)
      change(pos, val, lc, l, mid);
    else
      change(pos, val, rc, mid, r);
    mn[id] = min(mn[lc], mn[rc]);
  }
  void do_add(long long x, long long val) { change(rev[x], val); }
  long long get(long long x, long long y, long long id = 1, long long l = 0,
                long long r = N) {
    if (r <= x || l >= y) return inf;
    if (l >= x && r <= y) return mn[id];
    long long mid = (r + l) >> 1, lc = id << 1, rc = lc | 1;
    return min(get(x, y, lc, l, mid), get(x, y, rc, mid, r));
  }
} opt;
void pre_dfs(long long v = 0, long long p = -1) {
  st[v] = tim++;
  for (long long u : adj[v])
    if (u ^ p) pre_dfs(u, v);
  ft[v] = tim;
}
void update(long long id, long long val) {
  seg[id].lz += val;
  seg[id].mn += val;
}
void shift(long long id) {
  update(id << 1, seg[id].lz);
  update(id << 1 | 1, seg[id].lz);
  seg[id].lz = 0;
}
void add_value(long long x, long long y, long long val, long long id = 1,
               long long l = 0, long long r = n) {
  if (r <= x || l >= y) return;
  if (l >= x && r <= y) {
    update(id, val);
    return;
  }
  shift(id);
  long long mid = (r + l) >> 1, lc = id << 1, rc = lc | 1;
  add_value(x, y, val, lc, l, mid);
  add_value(x, y, val, rc, mid, r);
  seg[id].mn = min(seg[lc].mn, seg[rc].mn);
}
long long get_min(long long x, long long y, long long id = 1, long long l = 0,
                  long long r = n) {
  if (r <= x || l >= y) return inf;
  if (l >= x && r <= y) return seg[id].mn;
  shift(id);
  long long mid = (r + l) >> 1, lc = id << 1, rc = lc | 1;
  return min(get_min(x, y, lc, l, mid), get_min(x, y, rc, mid, r));
}
void dfs(long long v = 0, long long p = -1) {
  long long sum = 0;
  for (long long u : adj[v]) {
    if (u ^ p) {
      dfs(u, v);
      sum += dp[u];
    }
  }
  add_value(st[v], st[v] + 1, sum);
  for (long long u : adj[v]) {
    if (u ^ p) {
      add_value(st[u], ft[u], sum - dp[u]);
    }
  }
  for (long long x : add[v]) {
    opt.do_add(x, b[x].c);
  }
  for (long long x : rem[v]) {
    long long u = b[x].u;
    opt.do_add(x, inf);
    long long cost = opt.get(shuru[u], payan[u]);
    add_value(st[u], st[u] + 1, -ans[u]);
    ans[u] = cost;
    add_value(st[u], st[u] + 1, ans[u]);
  }
  ans[v] = opt.get(shuru[v], payan[v]);
  add_value(st[v], st[v] + 1, ans[v]);
  dp[v] = get_min(st[v], ft[v]);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (n == 1) {
    return cout << 0 << '\n', 0;
  }
  for (long long j = 0; j < n - 1; ++j) {
    long long u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (long long i = 0; i < m; ++i) {
    cin >> b[i].u >> b[i].v >> b[i].c;
    --b[i].u, --b[i].v;
    if (b[i].u && b[i].u == b[i].v) continue;
    add[b[i].u].push_back(i);
    if (b[i].v) rem[b[i].v].push_back(i);
  }
  for (long long i = 0; i < n; ++i) {
    shuru[i] = opt.ed;
    for (long long x : add[i]) opt.add_option(x);
    payan[i] = opt.ed;
  }
  pre_dfs();
  fill_n(dp, N, inf);
  dfs();
  if (dp[0] >= inf) dp[0] = -1;
  cout << dp[0] << '\n';
}