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 long long INF = 100000000000000ll;
const int N = 300010;
const int Nlg = N * 20;
struct EDGE {
  int u, v, nex;
  EDGE() {}
  EDGE(int _u, int _v, int _nex) {
    u = _u;
    v = _v;
    nex = _nex;
  }
} e[N * 2];
int len, fir[N];
int n, m, c[N], cal[N], rt[N];
long long f[N];
bool check;
vector<int> g[N];
struct TREE {
  int lc[Nlg], rc[Nlg], cnt;
  long long laz[Nlg], t[Nlg];
  void pdw(int u) {
    if (laz[u]) {
      if (lc[u]) t[lc[u]] += laz[u], laz[lc[u]] += laz[u];
      if (rc[u]) t[rc[u]] += laz[u], laz[rc[u]] += laz[u];
      laz[u] = 0;
    }
  }
  void pup(int u) {
    if (lc[u]) pdw(lc[u]);
    if (rc[u]) pdw(rc[u]);
    if (lc[u] && rc[u])
      t[u] = min(t[lc[u]], t[rc[u]]);
    else if (lc[u])
      t[u] = t[lc[u]];
    else if (rc[u])
      t[u] = t[rc[u]];
  }
  void modify(int &u, int l, int r, int p, long long c) {
    if (!u) u = ++cnt;
    pdw(u);
    if (l == r) {
      t[u] = c;
      return;
    }
    int mid = (l + r) / 2;
    if (p <= mid)
      modify(lc[u], l, mid, p, c);
    else
      modify(rc[u], mid + 1, r, p, c);
    pup(u);
  }
  void merge(int &u1, int u2) {
    if (!u1) {
      u1 = u2;
      return;
    }
    if (!u2) return;
    pdw(u1);
    pdw(u2);
    t[u1] = min(t[u1], t[u2]);
    merge(lc[u1], lc[u2]);
    merge(rc[u1], rc[u2]);
  }
} T;
void dfs1(int u, int fa) {
  for (int k = fir[u]; k != -1; k = e[k].nex) {
    int v = e[k].v;
    if (v == fa) continue;
    dfs1(v, u);
    cal[u] += cal[v];
  }
  int siz = g[u].size();
  for (int i = 0; i < siz; i++) cal[u] += (g[u][i] > 0 ? 1 : -1);
  if (u != 1 && !cal[u]) check = 0;
}
void dfs2(int u, int fa) {
  long long sum = 0;
  for (int k = fir[u]; k != -1; k = e[k].nex) {
    int v = e[k].v;
    if (v == fa) continue;
    dfs2(v, u);
    sum += f[v];
  }
  for (int k = fir[u]; k != -1; k = e[k].nex) {
    int v = e[k].v;
    if (v == fa) continue;
    T.laz[rt[v]] += sum - f[v];
    T.t[rt[v]] += sum - f[v];
    T.merge(rt[u], rt[v]);
  }
  int siz = g[u].size();
  for (int i = 0; i < siz; i++) {
    if (g[u][i] > 0)
      T.modify(rt[u], 1, m, g[u][i], c[g[u][i]] + sum);
    else
      T.modify(rt[u], 1, m, -g[u][i], INF);
  }
  f[u] = T.t[rt[u]];
  if (u == 1) f[u] = sum;
}
void addedge(int u, int v) {
  e[++len] = EDGE(u, v, fir[u]);
  fir[u] = len;
}
void read() {
  len = 0;
  memset(fir, -1, sizeof fir);
  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);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d%d", &u, &v, &c[i]);
    g[u].push_back(i);
    g[v].push_back(-i);
  }
}
void solve() {
  check = 1;
  dfs1(1, 0);
  if (!check) {
    printf("-1\n");
    return;
  }
  T.cnt = 0;
  dfs2(1, 0);
  printf("%I64d\n", f[1]);
}
int main() {
  read();
  solve();
  return 0;
}