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;
struct City {
  int idx;
  int depth;
  vector<int> children;
  vector<pair<int, int64_t>> costs;
};
std::vector<City> cities(300000 + 1);
auto cmp = [](const pair<int64_t, int> &city1,
              const pair<int64_t, int> &city2) {
  if (city1.first != city2.first) {
    return city1.first > city2.first;
  }
  return cities[city1.second].depth > cities[city2.second].depth;
};
struct SkewHeapNode {
  SkewHeapNode *left = nullptr, *right = nullptr;
  pair<int64_t, int> key;
  int64_t addition = 0;
  int dist = 0;
  static pair<int64_t, int> get_key(SkewHeapNode *node) {
    return {node->key.first + node->addition, node->key.second};
  }
  static pair<SkewHeapNode *, SkewHeapNode *> split(SkewHeapNode *node) {
    push(node);
    return {node->left, node->right};
  }
  static void push(SkewHeapNode *node) {
    if (node->left) node->left->addition += node->addition;
    if (node->right) node->right->addition += node->addition;
    node->key.first += node->addition;
    node->addition = 0;
  }
  static SkewHeapNode *merge(SkewHeapNode *first, SkewHeapNode *second) {
    if (first == nullptr) return second;
    if (second == nullptr) return first;
    push(first);
    push(second);
    if (first->key > second->key) swap(first, second);
    first->right = merge(first->right, second);
    if (!first->left || first->right->dist > first->left->dist) {
      swap(first->left, first->right);
    }
    first->dist = first->right ? (first->right->dist + 1) : 0;
    return first;
  }
  static void shift(SkewHeapNode *node, int64_t addition) {
    if (!node) return;
    node->addition += addition;
  }
};
class SkewHeap {
  SkewHeapNode *heap = nullptr;

 public:
  pair<int64_t, int> top() { return SkewHeapNode::get_key(heap); }
  void insert(pair<int64_t, int> key) {
    SkewHeapNode *node = new SkewHeapNode();
    node->key = key;
    heap = SkewHeapNode::merge(heap, node);
  }
  void pop() {
    auto spl = SkewHeapNode::split(heap);
    heap = SkewHeapNode::merge(spl.first, spl.second);
  }
  bool empty() { return !heap; }
  void shift(int64_t addition) { SkewHeapNode::shift(heap, addition); }
  void merge(SkewHeap &other) { heap = SkewHeapNode::merge(heap, other.heap); }
};
using SomeHeap = SkewHeap;
void dfs(int city, SomeHeap &heap, int as_only_child = -1) {
  if (cities[city].children.size() <= 1 || as_only_child >= 0) {
    if (as_only_child == -1) as_only_child = 0;
    if (!cities[city].children.empty()) {
      dfs(cities[city].children[as_only_child], heap);
    }
    while (!heap.empty() &&
           cities[heap.top().second].depth < cities[city].depth) {
      heap.pop();
    }
    int64_t currentCost = 0;
    if (!cities[city].children.empty()) {
      if (heap.empty()) throw "fug";
      currentCost = heap.top().first;
    }
    for (auto &kv : cities[city].costs) {
      heap.insert({currentCost + kv.second, kv.first});
    }
  } else {
    vector<SomeHeap> childGuts(cities[city].children.size());
    int64_t childTotal = 0;
    for (int i = 0; i < cities[city].children.size(); ++i) {
      dfs(cities[city].children[i], childGuts[i]);
      while (!childGuts[i].empty() &&
             cities[childGuts[i].top().second].depth < cities[city].depth) {
        childGuts[i].pop();
      }
      if (childGuts[i].empty()) throw "fug";
      childTotal += childGuts[i].top().first;
    }
    for (int i = 0; i < cities[city].children.size(); ++i) {
      int64_t thisChildAddition = childTotal - childGuts[i].top().first;
      childGuts[i].shift(thisChildAddition);
      heap.merge(childGuts[i]);
    }
    int64_t currentCost = heap.top().first;
    for (auto &kv : cities[city].costs) {
      heap.insert({currentCost + kv.second, kv.first});
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  unordered_map<int, vector<int>> edges;
  for (int i = 0; i < n - 1; ++i) {
    int p, c;
    cin >> p >> c;
    edges[p].push_back(c);
    edges[c].push_back(p);
  }
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    cities[u].costs.push_back({v, c});
  }
  {
    deque<int> stack{1};
    cities[1].depth = -1;
    vector<int> colored(300000 + 1);
    while (!stack.empty()) {
      int city = stack.back();
      stack.pop_back();
      colored[city] = 1;
      for (auto adjCity : edges[city]) {
        if (!colored[adjCity]) {
          cities[adjCity].depth = cities[city].depth - 1;
          cities[city].children.push_back(adjCity);
          stack.push_back(adjCity);
        }
      }
    }
  }
  {
    deque<int> stack{1};
    while (!stack.empty()) {
      int city = stack.back();
      stack.pop_back();
      for (auto childCity : cities[city].children) {
        stack.push_back(childCity);
      }
    }
  }
  SomeHeap heap;
  try {
    dfs(1, heap);
  } catch (...) {
    cout << -1 << endl;
    return 0;
  }
  cout << heap.top().first << endl;
  return 0;
}