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 double pi = acos(-1.0);
const long double eps = 1e-9;
const int INF = 1E9;
const long long LINF = 1E18;
const int MAXN = 300500;
const int MAXK = 524288;
struct vertex {
  long long val, upd;
  bool flag;
  vertex() { val = upd = flag = 0; }
};
vertex t[2 * MAXK + 3];
void initTree() {
  for (int i = 0; i < (int)(2 * MAXK + 3); i++) t[i].val = LINF;
}
long long add(long long a, long long x) {
  if (a == LINF) return a;
  a += x;
  if (a >= LINF) a = LINF;
  return a;
}
void push(int v, int L, int R) {
  if (t[v].flag) {
    if (R - L > 1) {
      t[2 * v].val = add(t[2 * v].val, t[v].upd);
      t[2 * v + 1].val = add(t[2 * v + 1].val, t[v].upd);
      t[2 * v].upd = add(t[2 * v].upd, t[v].upd);
      t[2 * v + 1].upd = add(t[2 * v + 1].upd, t[v].upd);
      t[2 * v].flag = t[2 * v + 1].flag = 1;
    }
    t[v].upd = 0;
    t[v].flag = 0;
  }
}
void upd(int v, int L, int R, int lx, int rx, long long x) {
  push(v, L, R);
  if (rx <= L || R <= lx) return;
  if (lx <= L && R <= rx) {
    t[v].val = add(t[v].val, x);
    t[v].upd = add(t[v].upd, x);
    t[v].flag = 1;
    return;
  }
  upd(v * 2, L, (L + R) >> 1, lx, rx, x);
  upd(v * 2 + 1, (L + R) >> 1, R, lx, rx, x);
  t[v].val = min(t[v * 2].val, t[v * 2 + 1].val);
}
void assign(int v, int L, int R, int pos, long long x) {
  push(v, L, R);
  if (L + 1 == R) {
    t[v].val = x;
    t[v].upd = 0;
    t[v].flag = 0;
    return;
  }
  if (pos < ((L + R) >> 1)) {
    assign(v * 2, L, (L + R) >> 1, pos, x);
  } else {
    assign(v * 2 + 1, (L + R) >> 1, R, pos, x);
  }
  t[v].val = min(t[v * 2].val, t[v * 2 + 1].val);
}
long long get(int v, int L, int R, int lx, int rx) {
  push(v, L, R);
  if (rx <= L || R <= lx) return LINF;
  if (lx <= L && R <= rx) return t[v].val;
  return min(get(v * 2, L, (L + R) >> 1, lx, rx),
             get(v * 2 + 1, (L + R) >> 1, R, lx, rx));
}
void upd(int L, int R, long long x) { upd(1, 1, MAXK + 1, L + 1, R + 2, x); }
void assign(int pos, long long x) { assign(1, 1, MAXK + 1, pos + 1, x); }
long long get(int L, int R) { return get(1, 1, MAXK + 1, L + 1, R + 2); }
int n, m;
int used[MAXN];
vector<int> g[MAXN];
vector<pair<int, int> > open[MAXN], close[MAXN];
int ptr, qPos[MAXN];
int lb[MAXN], rb[MAXN];
long long ans;
long long dp[MAXN], S[MAXN];
void dfs(int v) {
  used[v] = 1;
  lb[v] = ptr;
  for (auto q : open[v]) qPos[q.first] = ptr++;
  for (auto w : g[v])
    if (!used[w]) dfs(w);
  rb[v] = ptr - 1;
}
void calcDP(int v) {
  used[v] = 1;
  S[v] = 0;
  for (auto w : g[v])
    if (!used[w]) {
      calcDP(w);
      S[v] = add(S[v], dp[w]);
      upd(lb[w], rb[w], -dp[w]);
    }
  for (auto q : open[v]) assign(qPos[q.first], q.second);
  for (auto q : close[v]) assign(qPos[q.first], LINF);
  upd(lb[v], rb[v], S[v]);
  dp[v] = get(lb[v], rb[v]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < (int)(m); i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    open[a].push_back({i, c});
    close[b].push_back({i, c});
  }
  ptr = 0;
  dfs(0);
  initTree();
  memset(used, 0, sizeof(used));
  calcDP(0);
  ans = 0;
  for (auto v : g[0]) {
    ans = add(ans, dp[v]);
  }
  cout << (ans == LINF ? -1 : ans) << '\n';
  return 0;
}