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 = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return a > val ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
const int maxn = 300010;
int n, m;
vector<int> adj[maxn];
int c[maxn];
vector<int> add[maxn];
vector<int> del[maxn];
int tin[maxn];
int tou[maxn];
int eve[maxn];
int tms;
long long f[maxn];
long long st[maxn << 3];
long long lz[maxn << 3];
void updatelz(int node, int L, int R) {
  if (lz[node]) {
    st[node] += lz[node];
    chkmin(st[node], LINF);
    if (L < R) {
      lz[node << 1] += lz[node];
      lz[(node << 1) + 1] += lz[node];
    }
    lz[node] = 0;
  }
}
void update(int node, int i, int L, int R, long long val) {
  updatelz(node, L, R);
  if (i < L || i > R) return;
  if (L == R) {
    st[node] = val;
    return;
  }
  update(node << 1, i, L, L + R >> 1, val);
  update((node << 1) + 1, i, (L + R >> 1) + 1, R, val);
  st[node] = min(st[node << 1], st[(node << 1) + 1]);
}
void update(int node, int l, int r, int L, int R, long long val) {
  updatelz(node, L, R);
  if (l > R || r < L) return;
  if (l <= L && r >= R) {
    lz[node] += val;
    updatelz(node, L, R);
    return;
  }
  update(node << 1, l, r, L, L + R >> 1, val);
  update((node << 1) + 1, l, r, (L + R >> 1) + 1, R, val);
  st[node] = min(st[node << 1], st[(node << 1) + 1]);
}
long long query(int node, int l, int r, int L, int R) {
  updatelz(node, L, R);
  if (l > R || r < L) return LINF;
  if (l <= L && r >= R) return st[node];
  return min(query(node << 1, l, r, L, L + R >> 1),
             query((node << 1) + 1, l, r, (L + R >> 1) + 1, R));
}
void dfs(int u, int p = -1) {
  tin[u] = ++tms;
  for (int i = (0); i < (int((add[u]).size())); i++) {
    int k = add[u][i];
    eve[k] = ++tms;
  }
  long long tot = 0;
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      dfs(v, u);
      tot += f[v];
    }
  }
  tou[u] = tms;
  for (int i = (0); i < (int((add[u]).size())); i++) {
    int k = add[u][i];
    update(1, eve[k], 0, 2 * maxn - 1, tot + c[k]);
  }
  if (u) {
    for (int i = (0); i < (int((del[u]).size())); i++) {
      int k = del[u][i];
      update(1, eve[k], 0, 2 * maxn - 1, LINF);
    }
  }
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      update(1, tin[v], tou[v], 0, 2 * maxn - 1, tot - f[v]);
    }
  }
  f[u] = query(1, tin[u], tou[u], 0, 2 * maxn - 1);
  if (f[u] >= LINF) {
    puts("-1");
    exit(0);
  }
}
void solve() {
  for (int i = (0); i < (maxn << 3); i++) st[i] = LINF;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = (0); i < (m); i++) {
    int u, v;
    scanf("%d%d%d", &u, &v, c + i);
    u--;
    v--;
    add[u].push_back(i);
    del[v].push_back(i);
  }
  if (n == 1) {
    puts("0");
  } else {
    dfs(0);
    printf("%I64d\n", f[0]);
  }
}
int main() {
  solve();
  return 0;
}