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 mod = 1e9 + 7;
const int N = 3e5 + 10;
const long long inf = 1e10;
const long long INF = 1ll << 60;
inline long long read() {
  long long d = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch <= '9' && ch >= '0') d = d * 10 + ch - 48, ch = getchar();
  return d * w;
}
inline void file() {
  freopen(
      "a"
      ".in",
      "r", stdin);
  freopen(
      "a"
      ".out",
      "w", stdout);
}
int n, m;
long long ans;
int a[N], b[N], c[N];
int head[N], nxt[N << 1], to[N << 1], cnt;
inline void add(int u, int v) {
  to[++cnt] = v;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
int s[2][N], dis[N], lz[N];
inline void cover(int i, int v) {
  c[i] += v;
  lz[i] += v;
}
inline void pushdown(int i) {
  if (lz[i]) cover(s[0][i], lz[i]), cover(s[1][i], lz[i]), lz[i] = 0;
}
int merge(int a, int b) {
  if (!a || !b) return a | b;
  if (c[a] > c[b]) swap(a, b);
  pushdown(a);
  s[1][a] = merge(s[1][a], b);
  if (dis[s[0][a]] < dis[s[1][a]]) swap(s[0][a], s[1][a]);
  dis[a] = dis[s[1][a]] + 1;
  return a;
}
int rt[N], dep[N];
void dfs(int u, int ff) {
  dep[u] = dep[ff] + 1;
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v == ff) continue;
    dfs(v, u);
    rt[u] = merge(rt[u], rt[v]);
  }
  int &r = rt[u];
  while (r && dep[b[r]] >= dep[u]) pushdown(r), r = merge(s[0][r], s[1][r]);
  if (ff) {
    if (!r) puts("-1"), exit(0);
    ans += c[r];
    cover(r, -c[r]);
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 2, u, v; i <= n; i++) {
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= m; i++) {
    a[i] = read();
    b[i] = read();
    c[i] = read();
    rt[a[i]] = merge(rt[a[i]], i);
  }
  dfs(1, 0);
  printf("%I64d\n", ans);
  return 0;
}