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 nope() {
  printf("-1");
  exit(0);
}
int n, m;
int p1, p2;
long long p3;
vector<int> graf[1000007];
int wcho[1000007];
int oj[1000007];
vector<pair<long long, int> > wek[1100007];
int rep[1000007];
vector<int> lis;
int wsk[1000007];
long long wyn;
int n1;
pair<long long, int> drzewo[2100007];
long long narz[2100007];
int l;
int pre[1000007];
int post[1000007];
long long inf = (long long)100000000 * 100000000;
int potenga(int v) {
  for (int i = 1; 1; i <<= 1) {
    if (i >= v) {
      return i;
    }
  }
}
pair<long long, int> kana, kanb;
void pisz(int v, int a, int b, int graa, int grab, long long w) {
  if (a >= graa && b <= grab) {
    narz[v] += w;
    return;
  }
  if (a > grab || b < graa) {
    return;
  }
  pisz((v << 1), a, (a + b) >> 1, graa, grab, w);
  pisz((v << 1) ^ 1, (a + b + 2) >> 1, b, graa, grab, w);
  kana = drzewo[(v << 1)];
  kana.first += narz[(v << 1)];
  kanb = drzewo[(v << 1) ^ 1];
  kanb.first += narz[(v << 1) ^ 1];
  drzewo[v] = min(kana, kanb);
}
pair<long long, int> czyt(int v, int a, int b, int graa, int grab) {
  if (a >= graa && b <= grab) {
    kana = drzewo[v];
    kana.first += narz[v];
    return kana;
  }
  if (a > grab || b < graa) {
    return make_pair(inf, 0);
  }
  pair<long long, int> ra = czyt((v << 1), a, (a + b) >> 1, graa, grab);
  pair<long long, int> rb = czyt((v << 1) ^ 1, (a + b + 2) >> 1, b, graa, grab);
  ra = min(ra, rb);
  ra.first += narz[v];
  return ra;
}
int fin(int v) {
  if (v != oj[v]) oj[v] = fin(oj[v]);
  return oj[v];
}
int dajr(int v) { return rep[fin(v)]; }
void uni(int v, int u) {
  v = fin(v);
  u = fin(u);
  if (v == u) return;
  rep[v] = u;
  oj[v] = u;
}
void zje(int u) {
  u >>= 1;
  while (u) {
    kana = drzewo[(u << 1)];
    kana.first += narz[(u << 1)];
    kanb = drzewo[(u << 1) ^ 1];
    kanb.first += narz[(u << 1) ^ 1];
    drzewo[u] = min(kana, kanb);
    u >>= 1;
  }
}
void aktu(int v) {
  int u = pre[v] + n1 - 1;
  if (wek[v].empty()) {
    drzewo[u] = make_pair(inf, 0);
  } else {
    drzewo[u] = wek[v].back();
    drzewo[u].second = v;
  }
  zje(u);
}
void oddo(int v, int u) {
  u = dajr(u);
  while (1) {
    v = dajr(v);
    if (v == u) break;
    uni(v, wsk[v]);
  }
}
void dfs(int v, int w) {
  l++;
  pre[v] = l;
  for (int i = 0; i < graf[v].size(); i++) {
    if (graf[v][i] == w) continue;
    wsk[graf[v][i]] = v;
    dfs(graf[v][i], v);
  }
  l++;
  post[v] = l;
}
void zmni(int v, long long w) { pisz(1, 1, n1, pre[v], post[v], -w); }
void dfs2(int v) {
  for (int i = 0; i < graf[v].size(); i++) {
    if (graf[v][i] == wsk[v]) continue;
    dfs2(graf[v][i]);
  }
  if (v == 1 || dajr(v) != v) return;
  pair<long long, int> x;
  int cel;
  int u = fin(v);
  while (1) {
    x = czyt(1, 1, n1, pre[v], post[v]);
    if (!x.second) break;
    cel = wek[x.second].back().second;
    wek[x.second].pop_back();
    aktu(x.second);
    x.second = cel;
    x.second = fin(x.second);
    if (x.second == fin(v)) continue;
    zmni(v, x.first);
    wyn += x.first;
    oddo(v, x.second);
    return;
  }
  nope();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &p1, &p2);
    graf[p1].push_back(p2);
    graf[p2].push_back(p1);
    wcho[p1]++;
    wcho[p2]++;
  }
  for (int i = 1; i <= n; i++) {
    oj[i] = i;
    rep[i] = i;
    wcho[i]--;
  }
  wcho[1]++;
  dfs(1, 0);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%lld", &p1, &p2, &p3);
    wek[p1].push_back(make_pair(p3, p2));
  }
  for (int i = 1; i <= n; i++) {
    sort(wek[i].begin(), wek[i].end());
    reverse(wek[i].begin(), wek[i].end());
  }
  n1 = potenga(2 * n + 5);
  for (int i = 1; i <= n1; i++) {
    drzewo[i + n1 - 1] = make_pair(inf, 0);
    zje(i + n1 - 1);
  }
  for (int i = 1; i <= n; i++) {
    aktu(i);
  }
  dfs2(1);
  printf("%lld\n", wyn);
  return 0;
}