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>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
vector<int> edge[400000];
int depth[400000];
int par[400000];
int child[400000];
pair<pair<long long, long long>, int> a[400000];
vector<int> en[400000];
vector<int> st[400000];
void dback(int now, int parent) {
  child[now] = 1;
  for (auto e : edge[now]) {
    if (e == parent) continue;
    depth[e] = depth[now] + 1;
    par[e] = now;
    dback(e, now);
    child[now] += child[e];
  }
}
long long off[400000];
set<pair<long long, long long> > s[400000];
map<long long, long long> mq[400000];
long long d[400000];
void back(int now, int parent) {
  int mai = -1;
  long long dsum = 0;
  for (auto e : edge[now]) {
    if (e == parent) continue;
    back(e, now);
    dsum += d[e];
    if (mai == -1 || child[mai] < child[e]) mai = e;
  }
  if (mai != -1) {
    swap(s[now], s[mai]);
    swap(mq[now], mq[mai]);
    off[now] = off[mai] + dsum - d[mai];
  }
  for (auto e : edge[now]) {
    if (e == parent || e == mai) continue;
    for (auto f : s[e]) {
      s[now].emplace(f.first + off[e] - off[now] + dsum - d[e], f.second);
      mq[now][f.second] = f.first + off[e] - off[now] + dsum - d[e];
    }
    s[e].clear();
    mq[e].clear();
  }
  for (auto e : en[now]) {
    s[now].emplace(a[e].second + dsum - off[now], e);
    mq[now][e] = a[e].second + dsum - off[now];
  }
  if (parent != -1) {
    for (auto e : st[now]) {
      long long u = mq[now][e];
      s[now].erase(pair<long long, long long>(u, e));
      mq[now].erase(e);
    }
  }
  if (s[now].size() == 0) {
    printf("-1");
    exit(0);
  }
  d[now] = s[now].begin()->first + off[now];
}
int main() {
  int i, j, k, l;
  cin >> n >> m;
  if (n == 1) return !printf("0");
  for (i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y), x--, y--;
    edge[x].push_back(y), edge[y].push_back(x);
  }
  dback(0, -1);
  for (i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z), x--, y--;
    if (depth[x] > depth[y]) swap(x, y);
    a[i] = make_pair(make_pair(x, y), z);
    en[y].push_back(i);
    st[x].push_back(i);
  }
  back(0, -1);
  cout << d[0];
  return 0;
}