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;
const double pi = acos(-1.0);
const int mod = 1000000007;
void reduce(int &a) { a += a >> 31 & mod; }
int Mod(const int &x) { return x >= mod ? x - mod : x; }
long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 200010, M = N;
int n, m, fa[N][20], dep[N], siz[N], id[N], dfn[N], dfs_clock;
;
struct edge {
  int nxt, to, w;
} e[M << 1];
int head[N], ecnt = 1;
void add(int u, int v, int w = 0) {
  e[++ecnt] = {head[u], v, w}, head[u] = ecnt;
}
void add_edge(int u, int v, int w = 0) { add(u, v, w), add(v, u, w * 1); };
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int h = dep[u] - dep[v];
  for (int i = 0; i < 20; i++)
    if (h & (1 << i)) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19; ~i; i--)
    if (fa[u][i] != fa[v][i]) v = fa[v][i], u = fa[u][i];
  return fa[u][0];
}
void dfs(int u) {
  id[dfn[u] = ++dfs_clock] = u;
  for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  siz[u] = 1;
  for (int i = head[u], v; i; i = e[i].nxt)
    fa[v = e[i].to][0] = u, dep[v] = dep[u] + 1, dfs(v), siz[u] += siz[v];
}
vector<tuple<int, int, int> > vec[N];
int f[N], t[N];
void update(int l, int r, int v) {
  for (int i = l; i <= n; i += i & -i) t[i] += v;
  for (int i = r + 1; i <= n; i += i & -i) t[i] -= v;
}
int query(int i) {
  int res = 0;
  for (; i; i -= i & -i) res += t[i];
  return res;
}
void DP(int u) {
  int sum = 0;
  for (int i = head[u], v; i; i = e[i].nxt) DP(v = e[i].to), sum += f[v];
  f[u] = sum;
  for (auto i : vec[u]) {
    int x, y, w;
    tie(x, y, w) = i;
    f[u] = max(f[u], w + query(dfn[x]) + query(dfn[y]) + sum);
  }
  update(dfn[u], dfn[u] + siz[u] - 1, sum - f[u]);
}
int main() {
  n = read(), m = read();
  for (int i = 2; i <= n; i++) add(read(), i);
  dfs(1);
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), c = read();
    vec[lca(x, y)].push_back(make_tuple(x, y, c));
  }
  DP(1);
  ::print(f[1]), putchar('\n');
}