Problem: Masha is fond of cacti. When she was a little girl, she decided to plant a tree. Now Masha wants to make a nice cactus out of her tree.

Recall that tree is a connected undirected graph that has no cycles. Cactus is a connected undirected graph such that each vertex belongs to at most one cycle.

Masha has some additional edges that she can add to a tree. For each edge she knows which vertices it would connect and the beauty of this edge. Masha can add some of these edges to the graph if the resulting graph is a cactus. Beauty of the resulting cactus is sum of beauties of all added edges. 

Help Masha find out what maximum beauty of the resulting cactus she can achieve.

Input

The first line of the input data contains two integers n and m — the number of vertices in a tree, and the number of additional edges available (3 ≤ n ≤ 2·105; 0 ≤ m ≤ 2·105).

Let us describe Masha's tree. It has a root at vertex 1. The second line contains n - 1 integers: p2, p3, ..., pn, here pi — is the parent of a vertex i — the first vertex on a path from the vertex i to the root of the tree (1 ≤ pi < i).

The following m lines contain three integers ui, vi and ci — pairs of vertices to be connected by the additional edges that Masha can add to the tree and beauty of edge (1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ ci ≤ 104).

It is guaranteed that no additional edge coincides with the edge of the tree.

Output

Output one integer — the maximum beauty of a cactus Masha can achieve.

Example

Input

7 3
1 1 2 2 3 3
4 5 1
6 7 1
2 3 1


Output

2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
std::vector<int> E[200001];
std::vector<std::pair<std::pair<int, int>, int> > Path[200001];
int N, M, left[200001], right[200001], ref[200001], J[18][200001],
    *fa = J[0], LOG, dep[200001];
long long F[200001], T[524288], O;
void DFS() {
  static int q[200001];
  static std::vector<int>::iterator ue[200001];
  int D = 1, TIME = 1;
  q[1] = 1;
  ue[1] = E[1].begin();
  ref[left[1] = right[1] = 1] = 1;
  while (D)
    if (ue[D] != E[q[D]].end()) {
      int To = *ue[D]++;
      ref[left[To] = right[To] = ++TIME] = To;
      q[++D] = To;
      ue[D] = E[To].begin();
    } else {
      if (D > 1) right[q[D - 1]] = right[q[D]];
      D--;
    }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) std::swap(u, v);
  for (int i = LOG; ~i; i--)
    if (dep[u] - dep[v] >= 1 << i) u = J[i][u];
  if (u == v) return u;
  for (int i = LOG; ~i; i--)
    if (J[i][u] != J[i][v]) {
      u = J[i][u];
      v = J[i][v];
    }
  return fa[u];
}
long long G(int x) {
  int p = 1, l = 1, r = N;
  while (l < r) {
    int m = l + r >> 1;
    if (x <= m)
      p <<= 1, r = m;
    else
      p = p << 1 | 1, l = m + 1;
  }
  long long S = 0;
  while (p) {
    S += T[p];
    p >>= 1;
  }
  return S;
}
void P(int p, int l, int r, int L, int R, long long w) {
  if (L <= l && r <= R) {
    T[p] += w;
    return;
  }
  int m = l + r >> 1;
  if (L <= m) P(p << 1, l, m, L, R, w);
  if (R > m) P(p << 1 | 1, m + 1, r, L, R, w);
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 2; i <= N; i++) {
    scanf("%d", fa + i);
    E[fa[i]].push_back(i);
    dep[i] = dep[fa[i]] + 1;
  }
  while (2 << LOG < N) LOG++;
  for (int i = 1; i <= LOG; i++)
    for (int j = 1; j <= N; j++) J[i][j] = J[i - 1][J[i - 1][j]];
  DFS();
  while (M--) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    int lca = LCA(u, v);
    Path[lca].push_back({{u, v}, c});
  }
  for (int i = N; i; i--) {
    int u = ref[i];
    F[u] = 0;
    for (auto p : Path[u])
      F[u] = std::max(
          F[u], p.second - G(left[p.first.first]) - G(left[p.first.second]));
    P(1, 1, N, left[u], right[u], F[u]);
    O += F[u];
  }
  printf("%lld\n", O);
  return 0;
}