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 N = 6e5 + 5;
const long long INF = 1e16;
int n, m, ts, st[N], en[N], Id[N], C[N];
long long dp[N], Lz[N * 4], Mn[N * 4];
vector<int> Adj[N], A[N], B[N];
void DFS(int v, int p) {
  st[v] = ts++;
  for (int &i : A[v]) Id[i] = ts++;
  for (int &u : Adj[v])
    if (u != p) DFS(u, v);
  en[v] = ts;
}
inline void Shift(int id) {
  Lz[(id * 2)] += Lz[id];
  Mn[(id * 2)] = min(Mn[(id * 2)] + Lz[id], INF);
  Lz[(id * 2 + 1)] += Lz[id];
  Mn[(id * 2 + 1)] = min(Mn[(id * 2 + 1)] + Lz[id], INF);
  Lz[id] = 0;
}
void Add(int le, int ri, long long val, int id = 1, int l = 0, int r = N) {
  if (ri <= l || r <= le) return;
  if (le <= l && r <= ri) {
    Lz[id] += val;
    Mn[id] = min(Mn[id] + val, INF);
    return;
  }
  Shift(id);
  Add(le, ri, val, (id * 2), l, ((l + r) >> 1));
  Add(le, ri, val, (id * 2 + 1), ((l + r) >> 1), r);
  Mn[id] = min(Mn[(id * 2)], Mn[(id * 2 + 1)]);
}
long long Get(int le, int ri, int id = 1, int l = 0, int r = N) {
  if (ri <= l || r <= le) return (INF);
  if (le <= l && r <= ri) return (Mn[id]);
  Shift(id);
  return (min(Get(le, ri, (id * 2), l, ((l + r) >> 1)),
              Get(le, ri, (id * 2 + 1), ((l + r) >> 1), r)));
}
void DFS2(int v, int p) {
  long long s = 0;
  for (int &u : Adj[v])
    if (u != p) DFS2(u, v), s += dp[u];
  for (int &u : Adj[v])
    if (u != p) Add(st[u], en[u], s - dp[u]);
  for (int &i : A[v]) Add(Id[i], Id[i] + 1, C[i] + s - INF);
  dp[v] = min(Get(st[v], en[v]), INF);
  for (int &i : B[p]) Add(Id[i], Id[i] + 1, INF - Get(Id[i], Id[i] + 1));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, v, u; i < n; i++)
    scanf("%d%d", &v, &u), Adj[v].push_back(u), Adj[u].push_back(v);
  for (int i = 1, v, u; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &C[i]);
    if (v == u)
      m--, i--;
    else
      A[u].push_back(i), B[v].push_back(i);
  }
  DFS(1, 0);
  fill(Mn, Mn + N * 4, INF);
  long long s = 0;
  for (int &u : Adj[1]) {
    DFS2(u, 1);
    if (dp[u] == INF) return puts("-1");
    s += dp[u];
  }
  return !printf("%lld", s);
}