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 read() {
  int a = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a;
}
const int _ = 3e5 + 7, __ = _ * 19;
vector<int> nxt[_];
int N, M, dep[_];
void qdep(int x, int p) {
  dep[x] = dep[p] + 1;
  for (auto &t : nxt[x])
    if (t != p) qdep(t, x);
}
long long mrk[__], mn[__];
int ch[__][2], cnode;
void mark(int x, long long v) {
  if (x) {
    mrk[x] = min(mrk[x] + v, mn[0]);
    mn[x] = min(mn[x] + v, mn[0]);
  }
}
void down(int x) {
  if (x && mrk[x]) {
    mark((ch[x][0]), mrk[x]);
    mark((ch[x][1]), mrk[x]);
    mrk[x] = 0;
  }
}
void mdf(int &x, int l, int r, int t, long long v, bool type) {
  if (!type && !x) {
    x = ++cnode;
  }
  if (l == r) {
    mn[x] = type ? v : min(mn[x], v);
    return;
  }
  down(x);
  ((l + r) >> 1) >= t ? mdf((ch[x][0]), l, ((l + r) >> 1), t, v, type)
                      : mdf((ch[x][1]), ((l + r) >> 1) + 1, r, t, v, type);
  mn[x] = min(mn[(ch[x][0])], mn[(ch[x][1])]);
}
int merge(int p, int q) {
  if (!p || !q) {
    return p + q;
  }
  mn[p] = min(mn[p], mn[q]);
  down(p);
  down(q);
  ch[p][0] = merge(ch[p][0], ch[q][0]);
  ch[p][1] = merge(ch[p][1], ch[q][1]);
  return p;
}
vector<pair<int, int> > route[_];
int dfs(int x, int p) {
  long long vlsum = 0;
  int rt = 0;
  for (auto t : nxt[x])
    if (t != p) {
      int R = dfs(t, x);
      mdf(R, 1, N, dep[x] + 1, mn[0], 1);
      long long v = mn[R];
      mark(rt, v);
      mark(R, vlsum);
      vlsum = min(mn[0], vlsum + v);
      rt = merge(rt, R);
    }
  for (auto t : route[x]) mdf(rt, 1, N, t.first, vlsum + t.second, 0);
  if (x == 1) cout << (vlsum <= 1e16 ? vlsum : -1);
  return rt;
}
int main() {
  N = read();
  M = read();
  for (int i = 1; i < N; ++i) {
    int x = read(), y = read();
    nxt[x].push_back(y);
    nxt[y].push_back(x);
  }
  qdep(1, 0);
  for (int i = 1; i <= M; ++i) {
    int x = read(), y = read(), w = read();
    route[x].push_back(pair<int, int>(dep[y], w));
  }
  memset(mn, 0x3f, sizeof(mn));
  dfs(1, 0);
  return 0;
}