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;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}
const int N = 300009;
const long long Inf = 1e15 + 7;
int n, m;
int to[N << 1], nxt[N << 1], beg[N], val[N], tot;
int ord[N], id[N], ed[N], seg[N], fa[N], dfn;
long long f[N];
vector<int> in[N], out[N];
inline long long minn(long long a, long long b) {
  if (a < b) return a;
  return b;
}
namespace segt {
long long t[N << 2], tag[N << 2];
inline void mark(int x, long long v) {
  t[x] = minn(t[x] + v, Inf);
  tag[x] = minn(tag[x] + v, Inf);
}
inline void update(int x) { t[x] = minn(t[x << 1], t[x << 1 | 1]); }
inline void push(int x) {
  if (tag[x]) {
    mark(x << 1, tag[x]);
    mark(x << 1 | 1, tag[x]);
    tag[x] = 0;
  }
}
inline void build(int x, int l, int r) {
  if (l == r) {
    t[x] = Inf;
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  update(x);
}
inline void modify(int x, int l, int r, int p, long long v) {
  if (l == r) {
    t[x] = v;
    return;
  }
  push(x);
  int mid = l + r >> 1;
  if (p <= mid)
    modify(x << 1, l, mid, p, v);
  else
    modify(x << 1 | 1, mid + 1, r, p, v);
  update(x);
}
inline void add(int x, int l, int r, int dl, int dr, long long v) {
  if (dl == l && r == dr) {
    mark(x, v);
    return;
  }
  push(x);
  int mid = l + r >> 1;
  if (dr <= mid)
    add(x << 1, l, mid, dl, dr, v);
  else if (mid < dl)
    add(x << 1 | 1, mid + 1, r, dl, dr, v);
  else
    add(x << 1, l, mid, dl, mid, v),
        add(x << 1 | 1, mid + 1, r, mid + 1, dr, v);
  update(x);
}
inline long long query(int x, int l, int r, int dl, int dr) {
  if (dl == l && r == dr) return t[x];
  push(x);
  int mid = l + r >> 1;
  if (dr <= mid) return query(x << 1, l, mid, dl, dr);
  if (mid < dl) return query(x << 1 | 1, mid + 1, r, dl, dr);
  return minn(query(x << 1, l, mid, dl, mid),
              query(x << 1 | 1, mid + 1, r, mid + 1, dr));
}
}  // namespace segt
inline void add(int u, int v) {
  to[++tot] = v;
  nxt[tot] = beg[u];
  beg[u] = tot;
}
inline void dfs(int u) {
  id[u] = dfn + 1;
  for (int i = 0, e = in[u].size(); i < e; i++) ord[in[u][i]] = ++dfn;
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u]) {
      fa[to[i]] = u;
      dfs(to[i]);
    }
  ed[u] = dfn;
}
inline void dfs2(int u) {
  long long ans = 0;
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u]) {
      dfs2(to[i]);
      ans = minn(ans + f[to[i]], Inf);
    }
  if (u == 1) {
    f[1] = ans;
    return;
  }
  for (int i = 0, e = in[u].size(); i < e; i++)
    segt::modify(1, 1, m, ord[in[u][i]], ans + val[in[u][i]]);
  for (int i = 0, e = out[u].size(); i < e; i++)
    segt::modify(1, 1, m, ord[out[u][i]], Inf);
  for (int i = beg[u]; i; i = nxt[i])
    if (to[i] != fa[u] && id[to[i]] <= ed[to[i]])
      segt::add(1, 1, m, id[to[i]], ed[to[i]], ans - f[to[i]]);
  if (id[u] <= ed[u])
    f[u] = segt::query(1, 1, m, id[u], ed[u]);
  else
    f[u] = Inf;
}
int main() {
  if (fopen("vj.in", "r")) {
    freopen("vj.in", "r", stdin);
    freopen("vj.out", "w", stdout);
  }
  n = read();
  m = read();
  for (int i = 1, u, v; i < n; i++) {
    u = read();
    v = read();
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    val[i] = read();
    in[u].push_back(i);
    out[v].push_back(i);
  }
  dfs(1);
  segt::build(1, 1, m);
  dfs2(1);
  printf("%I64d\n", (f[1] == Inf) ? -1 : f[1]);
  return 0;
}