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;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const long long inf = 1e18;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
const int TREE_MAXV = 300000 + 5;
struct edge {
  int v, next;
} e[TREE_MAXV * 2];
int g[TREE_MAXV], etot;
int qu[TREE_MAXV], pre[TREE_MAXV];
int h[TREE_MAXV];
int n;
void ae(int u, int v) {
  e[etot].v = v;
  e[etot].next = g[u];
  g[u] = etot++;
}
void bfs(int rt) {
  int p = 0, q = 0;
  pre[rt] = 0;
  qu[q++] = rt;
  h[rt] = 0;
  while (p != q) {
    int u = qu[p++];
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u]) {
        pre[e[i].v] = u;
        qu[q++] = e[i].v;
        h[e[i].v] = h[u] + 1;
      }
  }
}
void tree_init() {
  static bool ini = 0;
  if (!ini) {
    ini = 1;
    memset(g, -1, sizeof(g));
  } else {
    for (int i = 0; i <= n; i++) g[i] = -1;
  }
  etot = 0;
}
void readedge() {
  for (int i = 1; i < n; i++) {
    int x, y;
    gn(x);
    gn(y);
    ae(x, y);
    ae(y, x);
  }
}
int m;
struct pat {
  int son, pre, co;
  void read() {
    gn(son);
    gn(pre);
    gn(co);
  }
} pa[333333];
vector<int> lis[333333];
map<int, long long> f[333333];
long long del[333333];
multiset<long long> mi[333333];
void inse(int id, int h, long long nu) {
  if (!f[id].count(h)) {
    f[id][h] = nu;
    mi[id].insert(nu);
  } else if (nu < f[id][h]) {
    multiset<long long>::iterator it = mi[id].find(f[id][h]);
    mi[id].erase(it);
    f[id][h] = nu;
    mi[id].insert(nu);
  }
}
void dp(int u) {
  int masz = -1, mav;
  for (int i = g[u]; ~i; i = e[i].next)
    if (e[i].v != pre[u]) {
      int v = e[i].v;
      if (upmax(masz, ((int)(f[v]).size()))) {
        mav = v;
      }
    }
  long long totmi = 0;
  if (masz != -1) {
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u]) {
        int v = e[i].v;
        if (mi[v].empty()) {
          printf("-1\n");
          exit(0);
        }
        totmi += *mi[v].begin() + del[v];
      }
    del[mav] += (totmi - (*mi[mav].begin() + del[mav]));
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u] && e[i].v != mav) {
        int v = e[i].v;
        for (__typeof((f[v]).begin()) it = (f[v]).begin(); it != (f[v]).end();
             it++) {
          inse(mav, it->first,
               it->second + del[v] + (totmi - *mi[v].begin() - del[v]) -
                   del[mav]);
        }
      }
    f[u].swap(f[mav]);
    mi[u].swap(mi[mav]);
    swap(del[u], del[mav]);
  } else {
    inse(u, h[u], 0);
  }
  for (int j = (0), _ed = (((int)(lis[u]).size())); j < _ed; j++) {
    int p = pa[lis[u][j]].pre;
    int c = pa[lis[u][j]].co;
    if (p == u) continue;
    int hi = h[p];
    inse(u, hi, c + totmi - del[u]);
  }
  if (u == 1) return;
  if (f[u].count(h[u])) {
    multiset<long long>::iterator it = mi[u].find(f[u][h[u]]);
    mi[u].erase(it);
    f[u].erase(h[u]);
  }
}
int main() {
  gn(n);
  gn(m);
  tree_init();
  readedge();
  for (int _ = (1), _ed = (m + 1); _ < _ed; _++) {
    pa[_].read();
    lis[pa[_].son].push_back(_);
  }
  bfs(1);
  for (int i = n - 1; i >= 0; i--) dp(qu[i]);
  cout << del[1] + f[1][0] << endl;
  return 0;
}