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 maxn = 3e5 + 10;
const long long INF = 1e18;
long long n, m, uu[maxn], vv[maxn], cc[maxn], indl[maxn], indr[maxn], ind[maxn],
    minn[4 * maxn], dp[4 * maxn], la[4 * maxn];
vector<int> adj[maxn], ord, sar[maxn], tah[maxn];
void dfs(long long v, long long p) {
  indl[v] = ord.size();
  for (auto u : adj[v])
    if (u != p) dfs(u, v);
  for (auto x : tah[v]) {
    ind[x] = ord.size();
    ord.push_back(x);
  }
  indr[v] = ord.size() - 1;
}
void build(long long l = 0ll, long long r = m - 1, long long node = 1ll) {
  if (l == r) {
    minn[node] = INF;
    return;
  }
  long long mid = (r + l) / 2;
  build(l, mid, 2 * node);
  build(mid + 1, r, (2 * node) + 1);
  minn[node] = INF;
}
void shift(long long l, long long r, long long node) {
  if (minn[node] != INF) minn[node] += la[node];
  if (l == r) {
    la[node] = 0;
    return;
  }
  la[2 * node] += la[node];
  la[(2 * node) + 1] += la[node];
  la[node] = 0;
}
void upd(long long x, long long y, long long va, long long l = 0ll,
         long long r = m - 1, long long node = 1ll) {
  shift(l, r, node);
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    minn[node] = va;
    return;
  }
  long long mid = (r + l) / 2;
  upd(x, y, va, l, mid, 2 * node);
  upd(x, y, va, mid + 1, r, (2 * node) + 1);
  minn[node] = min(minn[2 * node], minn[(2 * node) + 1]);
}
void add(long long x, long long y, long long va, long long l = 0ll,
         long long r = m - 1, long long node = 1ll) {
  shift(l, r, node);
  if (l > y || r < x) return;
  if (l >= x && r <= y) {
    la[node] += va;
    shift(l, r, node);
    return;
  }
  long long mid = (r + l) / 2;
  add(x, y, va, l, mid, 2 * node);
  add(x, y, va, mid + 1, r, (2 * node) + 1);
  minn[node] = min(minn[2 * node], minn[(2 * node) + 1]);
}
long long getmin(long long x, long long y, long long l = 0ll,
                 long long r = m - 1, long long node = 1ll) {
  shift(l, r, node);
  if (l > y || r < x) return INF;
  if (l >= x && r <= y) return minn[node];
  long long mid = (r + l) / 2;
  return min(getmin(x, y, l, mid, 2 * node),
             getmin(x, y, mid + 1, r, (2 * node) + 1));
}
void solve(long long v, long long p) {
  long long sum = 0;
  for (auto u : adj[v]) {
    if (u != p) {
      solve(u, v);
      sum += dp[u];
    }
  }
  for (auto x : tah[v]) upd(ind[x], ind[x], cc[x] + sum);
  for (auto x : sar[v]) upd(ind[x], ind[x], INF);
  for (auto u : adj[v])
    if (u != p) add(indl[u], indr[u], sum - dp[u]);
  dp[v] = getmin(indl[v], indr[v]);
  if (v == 1) return;
  if (dp[v] == INF) {
    cout << -1;
    exit(0);
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  for (int i = 1; i <= m; i++) {
    cin >> uu[i] >> vv[i] >> cc[i];
    sar[vv[i]].push_back(i);
    tah[uu[i]].push_back(i);
  }
  for (int i = 1; i <= 4 * m; i++) minn[i] = INF;
  dfs(1, 0);
  solve(1, 0);
  long long sum = 0;
  for (auto u : adj[1]) sum += dp[u];
  cout << sum;
  return 0;
}