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 int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
inline T sq(T a) {
  return a * a;
}
long long int in() {
  long long int x;
  scanf("%lld", &x);
  return x;
}
int n, m;
vector<int> G[300010];
int s[300010];
int t[300010];
long long int c[300010];
int id[300010];
vector<int> from[300010];
vector<int> to[300010];
long long int dp[300010];
long long int ans;
int cnt;
int inid[300010];
int outid[300010];
long long int node[2000010];
long long int added[2000010];
int size;
void init(int n) {
  size = 1;
  while (size < n) {
    size *= 2;
  }
}
void add(int a, int b, long long int x, int k, int l, int r) {
  if (a <= l and r <= b) {
    added[k] += x;
    chmin(added[k], INFLL);
  } else if (b <= l or r <= a) {
  } else {
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    node[k] = min(node[k * 2 + 1] + added[k * 2 + 1],
                  node[k * 2 + 2] + added[k * 2 + 2]);
    chmin(node[k], INFLL);
  }
}
void add(int a, int b, long long int x) { add(a, b, x, 0, 0, size); }
long long int query(int a, int b, int k, int l, int r) {
  if (a <= l and r <= b) {
    long long int res = node[k] + added[k];
    return min(res, INFLL);
  } else if (b <= l or r <= a) {
    return INFLL;
  } else {
    long long int chl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    long long int chr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    long long int res = min(chl, chr) + added[k];
    return min(res, INFLL);
  }
}
long long int query(int a, int b) { return query(a, b, 0, 0, size); }
void dfs(int x, int p) {
  inid[x] = cnt;
  long long int sum = 0;
  for (auto &w : G[x]) {
    if (w != p) {
      dfs(w, x);
      sum += dp[w];
    }
  }
  for (auto &w : G[x]) {
    if (w != p) {
      add(inid[w], outid[w], sum - dp[w]);
    }
  }
  for (auto &w : from[x]) {
    add(cnt, cnt + 1, sum + c[w]);
    id[w] = cnt;
    cnt++;
  }
  for (auto &w : to[x]) {
    add(id[w], id[w] + 1, INFLL);
  }
  outid[x] = cnt;
  dp[x] = query(inid[x], outid[x]);
  if (dp[x] == INFLL) {
    throw -1;
  }
}
int main() {
  n = in();
  m = in();
  init(m);
  for (long long int i = (0); i < (long long int)(n - 1); i++) {
    int a = in() - 1;
    int b = in() - 1;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  for (long long int i = (0); i < (long long int)(m); i++) {
    s[i] = in() - 1;
    t[i] = in() - 1;
    c[i] = in();
    from[s[i]].emplace_back(i);
    to[t[i]].emplace_back(i);
  }
  for (auto &w : G[0]) {
    try {
      dfs(w, 0);
      ans += dp[w];
    } catch (int e) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}