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 int N = 5e5 + 5;
const long long inf = (long long)1 << 60;
int n, m, tot = 0, head[N], dfsc = 0, st[N], ed[N];
long long f[N];
vector<int> in[N], out[N];
struct Edge {
  int to, nxt;
} e[N << 1];
inline void add(int from, int to) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
}
struct Querys {
  int x, y, pos;
  long long cost;
} q[N];
bool cmp(const Querys a, const Querys b) { return a.pos < b.pos; }
template <typename T>
inline void read(T &X) {
  X = 0;
  char ch = 0;
  T op = 1;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') op = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}
void dfs(int x, int fat) {
  st[x] = ++dfsc;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == fat) continue;
    dfs(y, x);
  }
  ed[x] = dfsc;
}
inline void chkMin(long long &x, long long y) {
  if (y < x) x = y;
}
inline long long min(long long x, long long y) { return x > y ? y : x; }
namespace SegT {
long long s[N << 2], tag[N << 2];
inline void up(int p) {
  if (p) s[p] = min(s[p << 1], s[p << 1 | 1]);
}
inline void done(int p, long long v) {
  tag[p] = min(inf, tag[p] + v);
  s[p] = min(inf, s[p] + v);
}
inline void down(int p) {
  if (tag[p] == 0LL) return;
  done(p << 1, tag[p]), done(p << 1 | 1, tag[p]);
  tag[p] = 0LL;
}
void build(int p, int l, int r) {
  s[p] = inf, tag[p] = 0LL;
  if (l == r) return;
  build(p << 1, l, ((l + r) >> 1));
  build(p << 1 | 1, ((l + r) >> 1) + 1, r);
}
void modifyP(int p, int l, int r, int x, long long v) {
  if (x == l && r == x) {
    s[p] = v;
    return;
  }
  down(p);
  if (x <= ((l + r) >> 1))
    modifyP(p << 1, l, ((l + r) >> 1), x, v);
  else
    modifyP(p << 1 | 1, ((l + r) >> 1) + 1, r, x, v);
  up(p);
}
void modify(int p, int l, int r, int x, int y, long long v) {
  if (x > y) return;
  if (x <= l && y >= r) {
    done(p, v);
    return;
  }
  down(p);
  if (x <= ((l + r) >> 1)) modify(p << 1, l, ((l + r) >> 1), x, y, v);
  if (y > ((l + r) >> 1)) modify(p << 1 | 1, ((l + r) >> 1) + 1, r, x, y, v);
  up(p);
}
long long query(int p, int l, int r, int x, int y) {
  if (x > y) return inf;
  if (x <= l && y >= r) return s[p];
  down(p);
  long long res = inf;
  if (x <= ((l + r) >> 1))
    res = min(res, query(p << 1, l, ((l + r) >> 1), x, y));
  if (y > ((l + r) >> 1))
    res = min(res, query(p << 1 | 1, ((l + r) >> 1) + 1, r, x, y));
  return res;
}
}  // namespace SegT
using namespace SegT;
inline int bfind(int x) {
  long long ln = 1, rn = m + 1, mid, res;
  for (; ln <= rn;) {
    mid = (ln + rn) / 2;
    if (q[mid].pos >= x)
      res = mid, rn = mid - 1;
    else
      ln = mid + 1;
  }
  return res;
}
void solve(int x, int fat) {
  long long sum = 0;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == fat) continue;
    solve(y, x);
    sum = min(inf, sum + f[y]);
  }
  if (x == 1) {
    f[1] = sum;
    return;
  }
  for (unsigned int i = 0; i < in[x].size(); i++)
    modifyP(1, 1, m, in[x][i], min(inf, q[in[x][i]].cost + sum));
  for (unsigned int i = 0; i < out[x].size(); i++)
    modifyP(1, 1, m, out[x][i], inf);
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == fat) continue;
    modify(1, 1, m, bfind(st[y]), bfind(ed[y] + 1) - 1, sum - f[y]);
  }
  f[x] = query(1, 1, m, bfind(st[x]), bfind(ed[x] + 1) - 1);
}
int main() {
  read(n), read(m);
  build(1, 1, m);
  for (int x, y, i = 1; i < n; i++) {
    read(x), read(y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  for (int i = 1; i <= m; i++) {
    read(q[i].x), read(q[i].y), read(q[i].cost);
    q[i].pos = st[q[i].x];
  }
  sort(q + 1, q + 1 + m, cmp);
  q[m + 1].pos = n + 1;
  for (int i = 1; i <= m; i++)
    in[q[i].x].push_back(i), out[q[i].y].push_back(i);
  solve(1, 0);
  if (f[1] >= inf)
    puts("-1");
  else
    printf("%lld\n", f[1]);
  return 0;
}