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;
struct Edge {
  int to, next;
} e[300010 * 2];
int c1, head[300010];
inline void add_edge(int u, int v) {
  e[c1].to = v;
  e[c1].next = head[u];
  head[u] = c1++;
}
struct node {
  int x, y;
  node() {}
  node(int _x, int _y) {
    x = _x;
    y = _y;
  }
};
struct seg {
  int ch[2];
  long long v, add;
  seg() {
    v = 1000000000000000000ll;
    add = 0;
  }
} T[300010 * 20];
int top, rt[300010];
void update(int &i, int l, int r, int k, long long v) {
  if (!i) i = ++top;
  T[i].v = min(T[i].v, v);
  if (l == r) return;
  int m = l + r >> 1;
  if (k <= m)
    update(T[i].ch[0], l, m, k, v);
  else
    update(T[i].ch[1], m + 1, r, k, v);
}
inline void seta(int i, long long v) {
  if (!i) return;
  T[i].v += v;
  T[i].add += v;
  T[i].v = min(T[i].v, 1000000000000000000ll);
  T[i].add = min(T[i].add, 1000000000000000000ll);
}
inline void push(int i) {
  seta(T[i].ch[0], T[i].add);
  seta(T[i].ch[1], T[i].add);
  T[i].add = 0;
}
void merge(int &i, int j) {
  if (!i) return (void)(i = j);
  if (!j) return;
  T[i].v = min(T[i].v, T[j].v);
  push(i);
  push(j);
  merge(T[i].ch[0], T[j].ch[0]);
  merge(T[i].ch[1], T[j].ch[1]);
}
long long query(int i, int l, int r, int k) {
  if (l == r) return T[i].v;
  int m = l + r >> 1;
  push(i);
  if (k <= m)
    return query(T[i].ch[0], l, m, k);
  else
    return min(T[T[i].ch[0]].v, query(T[i].ch[1], m + 1, r, k));
}
vector<node> A[300010];
int dep[300010];
long long f[300010];
void dfs(int u, int fa) {
  long long s = 0;
  for (auto it : A[u]) update(rt[u], 1, n, dep[it.x], it.y);
  for (int i = head[u]; ~i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    seta(rt[u], f[v]);
    seta(rt[v], s);
    merge(rt[u], rt[v]);
    s += f[v];
    s = min(s, 1000000000000000000ll);
  }
  f[u] = query(rt[u], 1, n, dep[u] - 1);
}
long long ans;
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d", &n, &m);
  if (n == 1) return puts("0"), 0;
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add_edge(x, y);
    add_edge(y, x);
  }
  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    A[x].push_back(node(y, z));
  }
  dep[1] = 1;
  dfs(1, 0);
  if (f[1] >= 1000000000000000000ll)
    puts("-1");
  else
    cout << f[1] << endl;
  return 0;
}