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 std::pair;
using std::vector;
const int MAXN = 3e5 + 20;
namespace IO_base {
const int MAXB = 1 << 10;
char gbuf[MAXB], *ps = gbuf, *pt = gbuf;
inline char Getchar() {
  if (ps == pt) {
    ps = gbuf;
    pt = gbuf + fread(gbuf, 1, MAXB, stdin);
  }
  return (ps == pt) ? EOF : *ps++;
}
}  // namespace IO_base
namespace IO_number {
int read() {
  int x = 0;
  char c = IO_base::Getchar();
  bool f = 0;
  while (c < '0' || c > '9')
    (c == '-') ? f = 1, c = IO_base::Getchar() : c = IO_base::Getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (48 ^ c), c = IO_base::Getchar();
  return (f) ? -x : x;
}
}  // namespace IO_number
using namespace IO_number;
namespace LeftistTree {
inline void _swap(int &x, int &y) { x ^= y ^= x ^= y; }
struct node {
  int rank, ls, rs;
  int key, cid;
  int tag;
  node(const pair<int, int> &_data)
      : rank(0), ls(0), rs(0), key(_data.first), cid(_data.second), tag(0) {}
};
vector<node> data(1, node(pair<int, int>(0, 0)));
inline int _min(const int &x, const int &y) {
  return (data[x].key < data[y].key) ? x : y;
}
inline void pushdown(const int &_x) {
  node &x = data[_x];
  if (x.tag) {
    data[x.ls].key += x.tag, data[x.ls].tag += x.tag;
    data[x.rs].key += x.tag, data[x.rs].tag += x.tag;
    x.tag = 0;
  }
}
int _merge(int x, int y) {
  if (!x || !y)
    return x + y;
  else {
    if (_min(x, y) == y) _swap(x, y);
    pushdown(x);
    data[x].rs = _merge(data[x].rs, y);
    if (data[data[x].ls].rank < data[data[x].rs].rank)
      _swap(data[x].ls, data[x].rs);
    data[x].rank = data[data[x].rs].rank + 1;
    return x;
  }
}
inline int pop_min(const int &rt) {
  pushdown(rt);
  return _merge(data[rt].ls, data[rt].rs);
}
inline int merge(const int &x, const int &y) { return _merge(x, y); }
inline void add_all(const int &x, const int &val) {
  data[x].key += val, data[x].tag += val;
}
int new_LT(const vector<pair<int, int> > &arr) {
  int rt = 0;
  for (pair<int, int> i : arr) {
    data.push_back(node(i));
    rt = merge(rt, data.size() - 1);
  }
  return rt;
}
}  // namespace LeftistTree
using namespace LeftistTree;
namespace Graph {
struct edge {
  int to, nxt;
  edge(const int &_to, const int &_nxt) : to(_to), nxt(_nxt) {}
};
vector<int> first;
vector<edge> e(1, edge(0, 0));
inline void addedge(const int &u, const int &v) {
  e.push_back(edge(v, first[u])), first[u] = e.size() - 1;
  e.push_back(edge(u, first[v])), first[v] = e.size() - 1;
}
}  // namespace Graph
using namespace Graph;
vector<vector<pair<int, int> > > chain_add;
vector<vector<int> > chain_del;
vector<bool> chain_is_del;
long long Ans;
int dfs(const int &u, const int &fa) {
  int rt = new_LT(chain_add[u]);
  for (int l = first[u]; l; l = e[l].nxt)
    if (e[l].to != fa) rt = merge(rt, dfs(e[l].to, u));
  for (int i : chain_del[u]) chain_is_del[i] = 1;
  while (rt && chain_is_del[LeftistTree::data[rt].cid]) rt = pop_min(rt);
  if (rt) {
    Ans += LeftistTree::data[rt].key;
    add_all(rt, -LeftistTree::data[rt].key);
  } else if (u != 1)
    puts("-1"), exit(0);
  return rt;
}
int main() {
  const int n = read(), m = read();
  first.resize(n + 1, 0), e.reserve(2 * (n - 1) + 1);
  for (int i = 0; i < n - 1; ++i) addedge(read(), read());
  chain_add.resize(n + 1), chain_del.resize(n + 1);
  chain_is_del.resize(m, 0);
  for (int i = 0; i < m; ++i) {
    const int _u = read(), _v = read(), _c = read();
    chain_add[_u].push_back(pair<int, int>(_c, i));
    chain_del[_v].push_back(i);
  }
  dfs(1, 0);
  printf("%lld", Ans);
}