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 char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void Read(int& x) {
  char c = nc();
  for (; c < '0' || c > '9'; c = nc())
    ;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - 48, c = nc())
    ;
}
vector<int> g[200010], a[200010];
int i, j, k, n, m, p, c[200010];
int f[200010];
int s[200010], t[200010], w[200010];
int L[200010], R[200010], num, F[200010][20], d[200010];
inline void Dfs(int x) {
  L[x] = ++num;
  d[x] = d[F[x][0]] + 1;
  for (int j = 1; j < 20; j++) F[x][j] = F[F[x][j - 1]][j - 1];
  for (int i = 0; i < g[x].size(); i++) Dfs(g[x][i]);
  R[x] = num;
}
inline int Lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = 20 - 1; i >= 0; i--)
    if (d[F[x][i]] >= d[y]) x = F[x][i];
  if (x == y) return x;
  for (int i = 20 - 1; i >= 0; i--)
    if (F[x][i] != F[y][i]) x = F[x][i], y = F[y][i];
  return F[x][0];
}
inline void Update(int x, int y) {
  for (; x <= n; x += x & -x) c[x] += y;
}
inline void Merge(int x, int y, int z) {
  Update(x, z);
  Update(y + 1, -z);
}
inline int Query(int x) {
  int Ans = 0;
  for (; x; x -= x & -x) Ans += c[x];
  return Ans;
}
inline void Solve(int x) {
  int S = 0;
  for (int i = 0; i < g[x].size(); i++) {
    Solve(g[x][i]);
    S += f[g[x][i]];
  }
  f[x] = S;
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    f[x] = max(f[x], Query(L[s[y]]) + Query(L[t[y]]) + S + w[y]);
  }
  Merge(L[x], R[x], S - f[x]);
}
int main() {
  Read(n);
  Read(m);
  for (i = 2; i <= n; i++) Read(F[i][0]), g[F[i][0]].push_back(i);
  Dfs(1);
  for (i = 1; i <= m; i++)
    Read(s[i]), Read(t[i]), Read(w[i]), a[Lca(s[i], t[i])].push_back(i);
  Solve(1);
  cout << f[1] << endl;
  return 0;
}