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>
int tot = 0, cnt = 0;
std::pair<long long, int> a[600005];
std::vector<std::pair<long long, int> > vec[300005];
int h[300005], to[600005], ver[600005];
int rt[300005], dep[300005], dis[600005], lson[600005], rson[600005];
long long f[300005], tag[600005];
inline int read() {
  register int x = 0, f = 1;
  register char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline void add(int x, int y) {
  to[++cnt] = y;
  ver[cnt] = h[x];
  h[x] = cnt;
}
inline void swap(int &x, int &y) {
  int tmp = y;
  y = x;
  x = tmp;
}
inline void work(int p, long long val) {
  tag[p] += val;
  a[p].first += val;
}
inline int spread(int p) {
  if (tag[p]) {
    work(lson[p], tag[p]);
    work(rson[p], tag[p]);
    tag[p] = 0;
  }
}
inline int merge(int x, int y) {
  if (!x || !y) return x + y;
  if (a[x].first > a[y].first) swap(x, y);
  spread(x);
  rson[x] = merge(rson[x], y);
  if (dis[rson[x]] > dis[lson[x]]) swap(lson[x], rson[x]);
  dis[x] = dis[rson[x]] + 1;
  return x;
}
inline void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  for (register int i = 0; i < vec[x].size(); ++i) {
    a[++tot] = std::make_pair(vec[x][i].first, vec[x][i].second);
    dis[tot] = 1;
    rt[x] = merge(rt[x], tot);
  }
  long long sum = 0;
  for (register int i = h[x]; i; i = ver[i]) {
    int y = to[i];
    if (y == fa) continue;
    dfs(y, x);
    work(rt[y], -f[y]);
    rt[x] = merge(rt[x], rt[y]);
    sum += f[y];
  }
  work(rt[x], sum);
  while (rt[x] && dep[x] <= dep[a[rt[x]].second]) {
    spread(rt[x]);
    rt[x] = merge(lson[rt[x]], rson[rt[x]]);
  }
  if (!rt[x]) {
    printf("-1\n", x);
    exit(0);
  }
  f[x] = a[rt[x]].first;
}
int main() {
  int n = read(), m = read();
  tot = n;
  dep[1] = 1;
  for (register int i = 1; i < n; ++i) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (register int i = 1; i <= m; ++i) {
    int x = read(), y = read(), k = read();
    vec[x].push_back(std::make_pair(k, y));
  }
  long long ans = 0;
  for (register int i = h[1]; i; i = ver[i]) {
    int y = to[i];
    dfs(y, 1);
    ans += f[y];
  }
  printf("%lld\n", ans);
  return 0;
}