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;
template <typename T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <typename T, typename... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <typename T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
template <typename T>
void _W(const vector<T> &x) {
  for (auto i = x.cbegin(); i != x.cend(); i++) {
    if (i != x.cbegin()) putchar(' ');
    _W(*i);
  }
}
void W() {}
template <typename T, typename... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
const int N = 3e5 + 10;
struct F {
  int to, len;
};
int n, m;
vector<int> e[N];
vector<F> f[N];
int dep[N], sz[N];
void dfs(int p, int lv) {
  dep[p] = -lv;
  sz[p] = ((int)(f[p]).size());
  for (int i : e[p]) {
    e[i].erase(find(begin(e[i]), end(e[i]), p));
    dfs(i, lv + 1);
    sz[p] += sz[i];
  }
  if (!e[p].empty()) {
    int w = 0;
    for (int i = 0; i < int(((int)(e[p]).size())); i++)
      if (sz[e[p][i]] > sz[e[p][w]]) w = i;
    swap(e[p][0], e[p][w]);
  }
}
inline void ins(map<int, long long> &mp, int k, long long v) {
  {
    auto it = mp.lower_bound(k);
    if (it != mp.end() && it->second <= v) return;
  }
  while (1) {
    auto it = mp.upper_bound(k);
    if (it == mp.begin()) break;
    it--;
    if (it->second < v) break;
    mp.erase(it);
  }
  mp[k] = v;
}
struct DP {
  long long d;
  map<int, long long> mp;
  void ins(int k, long long v) { ::ins(mp, k, v - d); }
  long long min() { return mp.begin()->second + d; }
};
inline void merge(DP &a, DP &b) {
  for (auto &i : b.mp) a.ins(i.first, i.second + b.d);
}
DP dp[N];
int dpi[N];
bool go(int p) {
  for (int i : e[p])
    if (!go(i)) return 0;
  long long base = 0;
  for (int i : e[p]) {
    auto &j = dp[dpi[i]];
    base += j.min();
  }
  for (int i : e[p]) {
    auto &j = dp[dpi[i]];
    j.d += base - j.min();
    if (!dpi[p])
      dpi[p] = dpi[i];
    else
      merge(dp[dpi[p]], j);
  }
  if (!dpi[p]) dpi[p] = p;
  auto &me = dp[dpi[p]];
  for (auto &i : f[p]) me.ins(dep[i.to], base + i.len);
  while (!me.mp.empty() && me.mp.begin()->first <= (dep[p] - (p == 1)))
    me.mp.erase(me.mp.begin());
  ;
  return !me.mp.empty();
}
int main() {
  R(n, m);
  if (n == 1) {
    W(0);
    return 0;
  }
  for (int i = 0; i < int(n - 1); i++) {
    int a, b;
    R(a, b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  for (int i = 0; i < int(m); i++) {
    int a, b, c;
    R(a, b, c);
    f[a].push_back(F{b, c});
  }
  dfs(1, 1);
  if (!go(1))
    W(-1);
  else
    W(dp[dpi[1]].min());
  return 0;
}