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;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
int n, m;
const int MAXN = 210000;
int s[MAXN], ans[2][MAXN], d[MAXN], dp[MAXN], a[MAXN], b[MAXN], c[MAXN],
    f[18][MAXN];
vector<int> adj[MAXN], V[MAXN];
inline int lca(int u, int v) {
  if (dp[u] < dp[v]) swap(u, v);
  for (int i = 0, diff = dp[u] - dp[v]; (1 << i) <= diff; i++)
    if (diff >> i & 1) u = f[i][u];
  if (u == v) return u;
  for (int i = 31 - __builtin_clz(dp[u]); i >= 0; i--)
    if (f[i][u] != f[i][v]) u = f[i][u], v = f[i][v];
  return f[0][u];
}
void add(int x, int y) {
  for (; x <= n; x += x & -x) d[x] += y;
}
int get(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += d[x];
  return ret;
}
int T;
void dfs(int u) {
  s[u] = ++T;
  ans[0][u] = 0;
  for (auto v : adj[u]) {
    dfs(v);
    ans[0][u] += ans[1][v];
  }
  ans[1][u] = 0;
  for (auto i : V[u]) {
    int x = s[a[i]], y = s[b[i]], z = c[i];
    chkmax(ans[1][u], get(x) + get(y) + c[i]);
  }
  add(s[u], -ans[1][u]);
  add(T + 1, ans[1][u]);
  ans[1][u] += ans[0][u];
}
int main() {
  scanf("%d%d", &n, &m);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &f[0][i]), dp[i] = dp[f[0][i]] + 1;
    for (int j = 1; j < 18; j++) f[j][i] = f[j - 1][f[j - 1][i]];
    adj[f[0][i]].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    V[lca(a[i], b[i])].push_back(i);
  }
  dfs(1);
  printf("%d\n", ans[1][1]);
  return 0;
}