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;
int n, m;
vector<int> v[300010];
class sgt {
 public:
  long long mn[1200010], tag[1200010];
  void pushnow(int p, long long v) {
    mn[p] += v;
    tag[p] += v;
  }
  void pushdown(int p) {
    if (tag[p]) {
      pushnow((p << 1), tag[p]);
      pushnow(((p << 1) | 1), tag[p]);
      tag[p] = 0;
    }
  }
  void set(int p, int l, int r, int pos, long long v) {
    if (l == r) {
      mn[p] = v;
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (pos <= mid)
      set((p << 1), l, mid, pos, v);
    else
      set(((p << 1) | 1), mid + 1, r, pos, v);
    mn[p] = min(mn[(p << 1)], mn[((p << 1) | 1)]);
  }
  void modify(int p, int l, int r, int ml, int mr, long long v) {
    if (ml <= l && r <= mr) {
      pushnow(p, v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);
    if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);
    mn[p] = min(mn[(p << 1)], mn[((p << 1) | 1)]);
  }
  long long query(int p, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return mn[p];
    pushdown(p);
    int mid = (l + r) >> 1;
    long long ret = 0x3f3f3f3f3f3f3f3f;
    if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
    if (qr > mid) ret = min(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
    return ret;
  }
} T;
int s[300010], e[300010], c[300010], id[300010], tim = 0, L[300010], R[300010];
long long f[300010];
vector<int> st[300010], ed[300010];
void dfs(int np, int fath) {
  L[np] = tim + 1;
  for (int &x : st[np]) id[x] = ++tim;
  for (int &x : v[np]) {
    if (x == fath) continue;
    dfs(x, np);
  }
  R[np] = tim;
  if (L[np] > R[np]) {
    puts("-1");
    exit(0);
  }
}
void dfs2(int np, int fath) {
  long long sum = 0;
  for (int &x : v[np]) {
    if (x == fath) continue;
    dfs2(x, np);
    sum += f[x];
  }
  for (int &x : ed[np]) T.set(1, 1, m, id[x], 0x3f3f3f3f3f3f3f3f);
  for (int &x : st[np]) T.modify(1, 1, m, id[x], id[x], sum);
  for (int &x : v[np]) {
    if (x == fath) continue;
    T.modify(1, 1, m, L[x], R[x], sum - f[x]);
  }
  f[np] = T.query(1, 1, m, L[np], R[np]);
  if (np != 1 && f[np] >= 1e18) {
    puts("-1");
    exit(0);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, ti, tj; i < n; i++) {
    scanf("%d%d", &ti, &tj);
    v[ti].push_back(tj);
    v[tj].push_back(ti);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &s[i], &e[i], &c[i]);
    st[s[i]].push_back(i);
    ed[e[i]].push_back(i);
  }
  dfs(1, 0);
  for (int i = 1; i <= m; i++) T.set(1, 1, m, id[i], c[i]);
  dfs2(1, 0);
  long long ans = 0;
  for (int &x : v[1]) ans += f[x];
  printf("%lld\n", ans);
  return 0;
}