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;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const long long bound = LINF >> 1;
struct SGT {
  struct node {
    int l, r;
    long long mn, delta;
  } a[1234567];
  void update(int p) { a[p].mn = min(a[p << 1].mn, a[p << 1 | 1].mn); }
  void push_down(int p) {
    if (a[p].delta != 0) {
      a[p].mn += a[p].delta;
      if (a[p].l < a[p].r) {
        a[p << 1].delta += a[p].delta;
        a[p << 1 | 1].delta += a[p].delta;
      }
      a[p].delta = 0;
    }
  }
  void build(int l, int r, int p = 1) {
    a[p].l = l;
    a[p].r = r;
    a[p].mn = LINF;
    a[p].delta = 0;
    if (l == r) return;
    int m = l + r >> 1;
    build(l, m, p << 1);
    build(m + 1, r, p << 1 | 1);
  }
  void set(int x, long long v, int p = 1) {
    push_down(p);
    int l = a[p].l, r = a[p].r;
    if (r < x || x < l) return;
    if (l == x && r == x) {
      a[p].mn = v;
      return;
    }
    set(x, v, p << 1);
    set(x, v, p << 1 | 1);
    update(p);
  }
  void add(int x, int y, long long v, int p = 1) {
    push_down(p);
    int l = a[p].l, r = a[p].r;
    if (r < x || y < l) return;
    if (x <= l && r <= y) {
      a[p].delta += v;
      push_down(p);
      return;
    }
    add(x, y, v, p << 1);
    add(x, y, v, p << 1 | 1);
    update(p);
  }
  long long query(int x, int y, int p = 1) {
    push_down(p);
    int l = a[p].l, r = a[p].r;
    if (x <= l && r <= y) return a[p].mn;
    int m = l + r >> 1;
    if (x <= m && m < y)
      return min(query(x, y, p << 1), query(x, y, p << 1 | 1));
    else if (x <= m)
      return query(x, y, p << 1);
    else
      return query(x, y, p << 1 | 1);
  }
} sgt;
long long c[300111];
int head[300111], to[600111], nxt[600111], tot;
int n, m, id[300111], idtot;
int tl[300111], tr[300111];
vector<int> qv[300111];
void init_dfs(int x, int pre) {
  tl[x] = idtot + 1;
  for (int i = 0; i < qv[x].size(); i++) {
    if (qv[x][i] > 0) {
      idtot++;
      id[qv[x][i]] = idtot;
    }
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == pre) continue;
    init_dfs(to[i], x);
  }
  tr[x] = idtot;
}
long long dfs(int x, int pre) {
  long long ans = 0;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == pre) continue;
    ans += dfs(to[i], x);
  }
  for (int i = 0; i < qv[x].size(); i++) {
    if (qv[x][i] > 0) {
      int j = qv[x][i];
      sgt.set(id[j], c[j]);
    } else {
      int j = -qv[x][i];
      sgt.set(id[j], LINF);
    }
  }
  if (x > 1) {
    long long tmp;
    if (tl[x] <= tr[x])
      tmp = sgt.query(tl[x], tr[x]);
    else
      tmp = LINF;
    if (tmp > bound) {
      cout << "-1" << endl;
      exit(0);
    }
    ans += tmp;
    sgt.add(tl[x], tr[x], -tmp);
  }
  return ans;
}
int main() {
  n = getnum(), m = getnum();
  for (int i = 1; i < n; i++) {
    int x, y;
    x = getnum(), y = getnum();
    nxt[++tot] = head[x];
    head[x] = tot;
    to[tot] = y;
    nxt[++tot] = head[y];
    head[y] = tot;
    to[tot] = x;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    long long cost;
    x = getnum(), y = getnum(), cost = getnum();
    qv[x].push_back(i);
    qv[y].push_back(-i);
    c[i] = cost;
  }
  init_dfs(1, -1);
  sgt.build(1, m);
  cout << dfs(1, -1) << endl;
  return 0;
}