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 maxn = 3E5 + 77;
const long long INF = 1E18 + 77;
char _mem[30000007];
int _cnt = 0;
void *alloc(size_t size) {
  void *ret = _mem + _cnt;
  _cnt += size;
  return ret;
}
void ans(long long v) {
  printf("%I64d\n", v);
  exit(0);
}
int N, M;
vector<pair<int, int> > W[maxn];
vector<pair<int, int> >::iterator WT[maxn];
vector<int> toDel[maxn];
struct EDGE {
  int to, next;
} edges[maxn * 2];
int cEdge = 1, head[maxn];
void addEdge(int from, int to) {
  edges[cEdge] = (EDGE){to, head[from]};
  head[from] = cEdge++;
}
struct SEG {
  SEG *ch[2];
  long long v, mn;
  void *operator new(size_t size) { return alloc(size); }
  void maintain() { mn = min(ch[0]->mn, ch[1]->mn) + v; }
} * tree;
void segInit(SEG *&tr = tree, int L = 1, int R = N) {
  tr = new SEG;
  if (L == R) return;
  int M = L + ((R - L) >> 1);
  segInit(tr->ch[0], L, M);
  segInit(tr->ch[1], M + 1, R);
}
void segAdd(SEG *tr, int L, int R, int qL, int qR, long long v) {
  if (qL == L && qR == R) {
    tr->v += v;
    tr->mn += v;
    return;
  }
  int M = L + ((R - L) >> 1);
  if (qR <= M)
    segAdd(tr->ch[0], L, M, qL, qR, v);
  else if (qL > M)
    segAdd(tr->ch[1], M + 1, R, qL, qR, v);
  else
    segAdd(tr->ch[0], L, M, qL, M, v),
        segAdd(tr->ch[1], M + 1, R, M + 1, qR, v);
  tr->maintain();
}
long long segQuery(SEG *tr, int L, int R, int qL, int qR) {
  if (qL == L && qR == R) return tr->mn;
  int M = L + ((R - L) >> 1);
  if (qR <= M)
    return segQuery(tr->ch[0], L, M, qL, qR) + tr->v;
  else if (qL > M)
    return segQuery(tr->ch[1], M + 1, R, qL, qR) + tr->v;
  else
    return min(segQuery(tr->ch[0], L, M, qL, M),
               segQuery(tr->ch[1], M + 1, R, M + 1, qR)) +
           tr->v;
}
int pre[maxn], suf[maxn], dfs_cnt, H[maxn], pa[maxn], cIn[maxn];
void dfs(int u, int f) {
  pre[u] = ++dfs_cnt;
  H[u] = H[f] + 1;
  pa[u] = f;
  ++cIn[f];
  for (int k = head[u]; k; k = edges[k].next) {
    int v = edges[k].to;
    if (v == f) continue;
    dfs(v, u);
  }
  suf[u] = dfs_cnt;
}
void solveW(int x) { sort(W[x].begin(), W[x].end()); }
long long dp[maxn];
void solve(int u) {
  for (vector<int>::iterator it = toDel[u].begin(); it != toDel[u].end();
       ++it) {
    int v = *it;
    long long cur = (WT[v]++)->first;
    while (WT[v] != W[v].end() && H[WT[v]->second] >= H[u]) ++WT[v];
    if (WT[v] == W[v].end())
      cur = INF;
    else {
      cur = WT[v]->first - cur;
      toDel[WT[v]->second].push_back(v);
    }
    segAdd(tree, 1, N, pre[v], pre[v], cur);
  }
  toDel[u].clear();
  long long s = 0;
  for (int k = head[u]; k; k = edges[k].next) {
    int v = edges[k].to;
    if (v == pa[u]) continue;
    s += dp[v];
  }
  if (u == 1) ans(s);
  segAdd(tree, 1, N, pre[u], pre[u], s);
  if (W[u].empty()) {
    segAdd(tree, 1, N, pre[u], pre[u], INF);
  } else {
    segAdd(tree, 1, N, pre[u], pre[u], WT[u]->first);
    toDel[WT[u]->second].push_back(u);
  }
  for (int k = head[u]; k; k = edges[k].next) {
    int v = edges[k].to;
    if (v == pa[u]) continue;
    segAdd(tree, 1, N, pre[v], suf[v], s - dp[v]);
  }
  dp[u] = segQuery(tree, 1, N, pre[u], suf[u]);
  if (dp[u] >= INF) ans(-1);
}
int Q[maxn], qhead, qrear;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i < N; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  while (M--) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    if (u != v) W[u].push_back(make_pair(c, v));
  }
  dfs(1, 0);
  for (int i = 1; i <= N; ++i) {
    solveW(i);
    WT[i] = W[i].begin();
    if (!cIn[i]) Q[qrear++] = i;
  }
  segInit();
  while (qhead < qrear) {
    int u = Q[qhead++];
    --cIn[pa[u]];
    if (!cIn[pa[u]]) Q[qrear++] = pa[u];
    solve(u);
  }
  printf("%I64d\n", dp[1]);
}