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 long long N = 3e5 + 5;
long long n, m;
vector<vector<long long> > a(N);
long long cost[N];
vector<vector<long long> > open(N), done(N);
long long sta[N], en[N], Time = 0;
long long posIT[N], dp[N];
const long long INF = numeric_limits<long long>::max() / 3;
void dfs(long long u, long long p) {
  sta[u] = Time + 1;
  for (auto id : open[u]) posIT[id] = ++Time;
  for (auto v : a[u]) {
    if (v == p) continue;
    dfs(v, u);
  }
  en[u] = Time;
}
class ITrangeMaxMin {
 public:
  long long n, f[4 * N], lazy[4 * N];
  void dolazy(long long k, long long l, long long r) {
    if (lazy[k] == 0) return;
    f[k] += lazy[k];
    f[k] = min(f[k], INF);
    if (l != r) {
      lazy[k * 2] += lazy[k];
      lazy[k * 2 + 1] += lazy[k];
    }
    lazy[k] = 0;
  }
  void init(long long k, long long l, long long r) {
    f[k] = lazy[k] = 0;
    if (l == r) return;
    init(k * 2, l, ((l + r) / 2));
    init(k * 2 + 1, ((l + r) / 2) + 1, r);
  }
  void update(long long k, long long l, long long r, long long L, long long R,
              long long val) {
    dolazy(k, l, r);
    if (r < L || R < l) return;
    if (L <= l && r <= R) {
      lazy[k] += val;
      dolazy(k, l, r);
      return;
    }
    update(k * 2, l, ((l + r) / 2), L, R, val);
    update(k * 2 + 1, ((l + r) / 2) + 1, r, L, R, val);
    f[k] = min(f[k * 2], f[k * 2 + 1]);
  }
  long long get(long long k, long long l, long long r, long long L,
                long long R) {
    dolazy(k, l, r);
    if (r < L || R < l) return INF;
    if (L <= l && r <= R) return f[k];
    return min(get(k * 2, l, ((l + r) / 2), L, R),
               get(k * 2 + 1, ((l + r) / 2) + 1, r, L, R));
  }
  void init(long long _n) {
    n = _n;
    init(1, 0, n + 1);
  }
  long long get(long long l, long long r) { return get(1, 0, n + 1, l, r); };
  void update(long long l, long long r, long long val) {
    update(1, 0, n + 1, l, r, val);
  };
} IT;
ostream &operator<<(ostream &os, const ITrangeMaxMin &X) {
  for (long long i = (long long)1; i <= (long long)X.n; i++)
    os << IT.get(i, i) << ' ';
  return os;
}
long long solve(long long u, long long p) {
  long long &ret = dp[u];
  if (ret != -1) return ret;
  ret = INF;
  long long sum = 0;
  for (auto v : a[u]) {
    if (v == p) continue;
    sum += solve(v, u);
    sum = min(sum, INF);
  }
  if (u == 1) {
    ret = sum;
    return ret;
  }
  for (auto id : open[u]) {
    IT.update(posIT[id], posIT[id], cost[id] + sum);
  }
  for (auto id : done[u]) {
    IT.update(posIT[id], posIT[id], INF);
  }
  for (auto v : a[u]) {
    if (v == p) continue;
    IT.update(sta[v], en[v], sum - solve(v, u));
  }
  ret = min(ret, IT.get(sta[u], en[u]));
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = (long long)1; i <= (long long)n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (long long i = (long long)1; i <= (long long)m; i++) {
    long long u, v;
    cin >> u >> v >> cost[i];
    open[u].push_back(i);
    done[v].push_back(i);
  }
  IT.init(m);
  memset(dp, -1, sizeof(dp));
  dfs(1, 1);
  solve(1, 1);
  if (dp[1] == INF)
    cout << -1 << '\n';
  else
    cout << dp[1] << '\n';
}