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>
void read(T &t) {
  t = 0;
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  do {
    (t *= 10) += ch - '0';
    ch = getchar();
  } while ('0' <= ch && ch <= '9');
  t *= f;
}
const long long INF = 1LL << 50;
const int maxn = (3e5) + 10;
int n, m, tot, nxt[maxn * 2], to[maxn * 2], head[maxn], dfn[maxn], sz[maxn];
long long tr[maxn * 4], dp[maxn], lazy[maxn * 4];
int tL[maxn], tR[maxn], vL[maxn], vR[maxn];
vector<int> in[maxn], out[maxn];
struct node {
  int x, y;
  long long z;
} d[maxn];
bool cmp(node A, node B) { return dfn[A.x] < dfn[B.x]; }
void add(int x, int y) {
  tot++;
  nxt[tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
void DFS(int u, int p) {
  dfn[u] = ++tot;
  sz[u] = 1;
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v != p) DFS(v, u), sz[u] += sz[v];
  }
}
void F(long long &x, long long y) {
  x += y;
  if (x > INF) x = INF;
}
void pushdown(int root) {
  if (!lazy[root]) return;
  F(tr[root * 2], lazy[root]);
  F(tr[root * 2 + 1], lazy[root]);
  F(lazy[root * 2], lazy[root]);
  F(lazy[root * 2 + 1], lazy[root]);
  lazy[root] = 0;
}
void add(int L, int R, int l, int r, int root, long long delta, bool flag = 0) {
  if (L > R) return;
  if (L <= l && r <= R) {
    if (flag)
      F(tr[root], delta), F(lazy[root], delta);
    else
      tr[root] = delta;
    return;
  }
  pushdown(root);
  int mid = (l + r) / 2;
  if (L <= mid) add(L, R, l, mid, root * 2, delta, flag);
  if (mid < R) add(L, R, mid + 1, r, root * 2 + 1, delta, flag);
  tr[root] = min(tr[root * 2], tr[root * 2 + 1]);
}
long long query(int L, int R, int l, int r, int root) {
  if (L > R) return INF;
  if (L <= l && r <= R) return tr[root];
  pushdown(root);
  int mid = (l + r) / 2;
  long long res = INF;
  if (L <= mid) res = min(res, query(L, R, l, mid, root * 2));
  if (mid < R) res = min(res, query(L, R, mid + 1, r, root * 2 + 1));
  return res;
}
void dfs(int u, int p) {
  long long sum = 0;
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v != p) {
      dfs(v, u);
      F(sum, dp[v]);
    }
  }
  if (sum >= INF) {
    printf("-1\n");
    exit(0);
  }
  if (u == 1) {
    printf("%lld\n", sum);
    exit(0);
  }
  for (int i = 0, id; i < in[u].size(); i++) {
    id = in[u][i];
    add(id, id, 1, m, 1, sum + d[id].z);
  }
  for (int i = 0, id; i < out[u].size(); i++) {
    id = out[u][i];
    add(id, id, 1, m, 1, INF);
  }
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v != p) add(vL[v], vR[v], 1, m, 1, sum - dp[v], 1);
  }
  dp[u] = query(vL[u], vR[u], 1, m, 1);
}
int main() {
  read(n);
  read(m);
  int x, y;
  for (int i = 1; i < n; i++) {
    read(x);
    read(y);
    add(x, y);
    add(y, x);
  }
  tot = 0;
  DFS(1, 0);
  for (int i = 1; i <= m; i++) read(d[i].x), read(d[i].y), read(d[i].z);
  sort(d + 1, d + m + 1, cmp);
  for (int i = 1; i <= n; i++) tL[i] = m + 1;
  for (int i = 1; i <= m; i++) {
    x = dfn[d[i].x];
    tL[x] = min(tL[x], i);
    tR[x] = max(tR[x], i);
    in[d[i].x].push_back(i);
    out[d[i].y].push_back(i);
  }
  for (int i = 1; i <= n; i++) tR[i] = max(tR[i], tR[i - 1]);
  for (int i = n - 1; i >= 1; i--) tL[i] = min(tL[i], tL[i + 1]);
  for (int i = 1; i <= n; i++) {
    vL[i] = tL[dfn[i]];
    vR[i] = tR[dfn[i] + sz[i] - 1];
  }
  for (int i = 1; i <= n * 4; i++) tr[i] = INF;
  dfs(1, 0);
  return 0;
}