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, head[300005], deep[300005];
long long val[300005];
vector<pair<long long, int> > ins[300005];
struct graph {
  int next, to;
  graph() {}
  graph(int _next, int _to) : next(_next), to(_to) {}
} edge[300005 * 2];
inline void add(int x, int y) {
  static int cnt = 1;
  edge[++cnt] = graph(head[x], y);
  head[x] = cnt;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct heap {
  struct node {
    static node *nil;
    node *son[2];
    pair<long long, int> key;
    long long tag;
    int npl;
    node() : npl(-1) { key = make_pair((long long)1e18, 0); }
    node(pair<long long, int> _key) : key(_key), tag(0), npl(0) {
      son[0] = son[1] = nil;
    }
    void pushdown() {
      son[0]->tag += tag, son[1]->tag += tag;
      son[0]->key.first += tag, son[1]->key.first += tag;
      tag = 0;
    }
  };
  node *root;
  heap() { root = node::nil; }
  node *merge(node *x, node *y) {
    if (x == node::nil) return y;
    if (y == node::nil) return x;
    if (x->key > y->key) swap(x, y);
    if (x->tag) x->pushdown();
    x->son[1] = merge(x->son[1], y);
    if (x->son[0]->npl < x->son[1]->npl) swap(x->son[0], x->son[1]);
    x->npl = x->son[1]->npl + 1;
    return x;
  }
  void push(pair<long long, int> x) {
    node *c = new node(x);
    root = merge(root, c);
  }
  pair<long long, int> top() { return root->key; }
  void pop() {
    root->pushdown();
    root = merge(root->son[0], root->son[1]);
  }
  bool empty() { return root == node::nil; }
  void modify(long long x) {
    root->key.first += x;
    root->tag += x;
  }
  void join(heap &h) { root = merge(root, h.root); }
};
heap::node *heap::node::nil = new heap::node();
heap s[300005];
void solve(int x, int fa) {
  deep[x] = deep[fa] + 1;
  long long sum = 0;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].to != fa) solve(edge[i].to, x), sum += val[edge[i].to];
  while (!s[x].empty() && deep[s[x].top().second] >= deep[x]) s[x].pop();
  for (auto i : ins[x]) s[x].push({i.first, i.second});
  if (x == 1) {
    cout << sum << endl;
    exit(0);
  }
  if (s[x].empty()) {
    cout << -1 << endl;
    exit(0);
  }
  val[x] = sum + s[x].top().first;
  s[x].modify(sum - val[x]);
  s[fa].join(s[x]);
}
int main() {
  cin >> n >> m;
  for (int x, y, i = 1; i < n; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  for (int u, v, c, i = 1; i <= m; ++i) {
    u = read(), v = read(), c = read();
    if (u != v) ins[u].push_back({c, v});
  }
  solve(1, 0);
  return 0;
}