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>
const int max_N = 302401;
int n, m, A[max_N], B[max_N], C[max_N], dep[max_N];
std::vector<int> T[max_N], Cd[max_N], Cu[max_N];
long long ans;
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = true;
  while (!isdigit(c)) flag &= (c != '-'), c = getchar();
  while (isdigit(c)) ans = 10 * ans + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    Write(x / 10), putchar(x % 10 + '0');
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
void _min(int &x, int y) {
  if (x > y) x = y;
}
void _max(int &x, int y) {
  if (x < y) x = y;
}
namespace pairing_heap {
int son[max_N][2], root[max_N], val[max_N], tag[max_N];
void change(int rt, int x) {
  if (rt) tag[rt] += x, val[rt] += x;
}
void pushdown(int rt) {
  if (tag[rt])
    change(son[rt][0], tag[rt]), change(son[rt][1], tag[rt]), tag[rt] = 0;
}
int merge(int x, int y) {
  assert(!son[x][1] && !son[y][1]);
  if (!x || !y) return x | y;
  pushdown(x), pushdown(y);
  if (val[x] > val[y]) std::swap(x, y);
  return son[y][1] = son[x][0], son[x][0] = y, x;
}
void link(int x, int y) { root[y] = merge(x, root[y]); }
int del(int rt) {
  pushdown(rt);
  int x = son[rt][0], y = son[x][1];
  if (!x) return 0;
  if (!y) return x;
  pushdown(x), pushdown(y);
  son[rt][0] = son[y][1], son[x][1] = son[y][1] = 0;
  return merge(merge(x, y), del(rt));
}
void pop(int x) { root[x] = del(root[x]); }
}  // namespace pairing_heap
void dfs(int x, int fa) {
  using namespace pairing_heap;
  dep[x] = dep[fa] + 1;
  for (auto i : T[x])
    if (i != fa) dfs(i, x), link(pairing_heap::root[i], x);
  while (root[x] && dep[B[root[x]]] >= dep[x]) pop(x);
  for (auto i : Cd[x]) link(i, x);
  if (!root[x]) puts("-1"), exit(0);
  ans += val[root[x]], change(root[x], -val[root[x]]);
}
int main() {
  n = read(), m = read();
  for (int i = 1, u, v; i < n; i++)
    u = read(), v = read(), T[u].push_back(v), T[v].push_back(u);
  for (int i = 1; i <= m; i++) {
    A[i] = read(), B[i] = read(), C[i] = read();
    if (A[i] != B[i])
      Cd[A[i]].push_back(i), Cu[B[i]].push_back(i), pairing_heap::val[i] = C[i];
  }
  for (auto i : T[1]) dfs(i, 1);
  return Write(ans), 0;
}