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>
using namespace std;
inline int read() {
  int x;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';) x = x * 10 + c - '0';
  return x;
}
struct edge {
  int nx, t;
} e[200000 + 5];
int h[200000 + 5], en, s[200000 + 5], mx[200000 + 5], d[200000 + 5],
    fa[200000 + 5], f[200000 + 5], l[200000 + 5], p[200000 + 5], cnt,
    t[262144 * 2 + 5], F[200000 + 5];
vector<pair<pair<int, int>, int> > v[200000 + 5];
inline void ins(int x, int y) {
  e[++en] = (edge){h[x], y};
  h[x] = en;
}
void add(int k, int x) {
  for (k += 262144; k; k >>= 1) t[k] += x;
}
int query(int l, int r) {
  int res = 0;
  if (l <= r)
    for (l += 262144 - 1, r += 262144 + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) res += t[l + 1];
      if (r & 1) res += t[r - 1];
    }
  return res;
}
void dfs(int x) {
  s[x] = 1;
  for (int i = h[x]; i; i = e[i].nx) {
    fa[e[i].t] = x;
    d[e[i].t] = d[x] + 1;
    dfs(e[i].t);
    s[x] += s[e[i].t];
    if (s[e[i].t] > s[mx[x]]) mx[x] = e[i].t;
  }
}
void build(int x) {
  p[l[x] = ++cnt] = x;
  if (mx[x]) f[mx[x]] = f[x], build(mx[x]);
  for (int i = h[x]; i; i = e[i].nx)
    if (e[i].t != mx[x]) build(f[e[i].t] = e[i].t);
}
int lca(int x, int y) {
  while (f[x] != f[y])
    if (d[f[x]] > d[f[y]])
      x = fa[f[x]];
    else
      y = fa[f[y]];
  return d[x] < d[y] ? x : y;
}
int up(int x, int y) {
  for (; f[x] != f[y]; x = fa[f[x]])
    if (fa[f[x]] == y) return f[x];
  return p[l[y] + 1];
}
int Q(int x, int y) {
  int res = 0;
  for (; f[x] != f[y]; x = fa[f[x]])
    res += query(l[f[x]], l[x]) + F[mx[x]] - F[f[x]];
  return res + query(l[y], l[x]) + F[mx[x]];
}
void dp(int x) {
  for (int i = h[x]; i; i = e[i].nx) dp(e[i].t), F[x] += F[e[i].t];
  add(l[x], F[x] - F[mx[x]]);
  for (int i = 0; i < v[x].size(); ++i) {
    int y = up(v[x][i].first.first, x);
    F[x] = max(F[x], Q(v[x][i].first.first, y) + Q(v[x][i].first.second, x) -
                         F[y] + v[x][i].second);
  }
}
int main() {
  int n, m, i, x, y;
  n = read();
  m = read();
  for (i = 2; i <= n; ++i) ins(read(), i);
  dfs(1);
  build(f[1] = 1);
  while (m--) {
    i = lca(x = read(), y = read());
    if (x == i) swap(x, y);
    v[i].push_back(make_pair(make_pair(x, y), read()));
  }
  dp(1);
  printf("%d", F[1]);
}