#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;
}
