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>
void chkmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chkmax(T &a, T b) {
  a = max(a, b);
}
inline int fread(void) {
  int ret = 0, op = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) - '0' + ch;
  return ret * op;
}
const int MAXN = 2e5 + 10;
const int MAXM = +10;
int n, m, head[MAXN], nxt[MAXN << 1], to[MAXN << 1], ind;
inline void add_edge(int u, int v) {
  nxt[++ind] = head[u];
  head[u] = ind;
  to[ind] = v;
}
inline void add(int u, int v) {
  add_edge(u, v);
  add_edge(v, u);
}
struct BIT {
  int t[MAXN];
  int lowbit(int x) { return x & (-x); }
  void add(int x, int v) {
    for (; x <= n; x += lowbit(x)) t[x] += v;
  }
  int ask(int x) {
    int ret = 0;
    for (; x; x -= lowbit(x)) ret += t[x];
    return ret;
  }
} T;
struct rec {
  int u, v, val;
  rec() { u = v = val = 0; }
  rec(int _u, int _v, int _val) : u(_u), v(_v), val(_val) {}
};
vector<rec> Q[MAXN];
int siz[MAXN], son[MAXN], fa[MAXN], depth[MAXN], dfn[MAXN], Top[MAXN], cnt;
void dfs1(int u, int fath) {
  fa[u] = fath;
  siz[u] = 1;
  depth[u] = depth[fath] + 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fath) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[son[u]] < siz[v]) son[u] = v;
  }
}
void dfs2(int u, int topn) {
  Top[u] = topn;
  dfn[u] = ++cnt;
  if (son[u]) dfs2(son[u], topn);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
int LCA(int u, int v) {
  while (Top[u] != Top[v]) {
    if (depth[Top[u]] < depth[Top[v]]) swap(u, v);
    u = fa[Top[u]];
  }
  if (depth[u] > depth[v]) swap(u, v);
  return u;
}
inline void init(void) {
  n = fread();
  m = fread();
  int x;
  for (int i = 2; i <= n; ++i) {
    x = fread();
    add(i, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  int u, v, val;
  for (int i = 1; i <= m; ++i) {
    u = fread(), v = fread(), val = fread();
    int lca = LCA(u, v);
    Q[lca].push_back(rec(u, v, val));
  }
}
void modify(int x, int v) {
  T.add(dfn[x], v);
  T.add(dfn[x] + siz[x], -v);
}
int query(int u, int v, int lca) {
  return T.ask(dfn[u]) + T.ask(dfn[v]) - 2 * T.ask(dfn[lca]);
}
int f[MAXN], sum[MAXN];
void TreeDP(int u, int fa) {
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    TreeDP(v, u);
    sum[u] += f[v];
  }
  f[u] = sum[u];
  for (int i = 0; i < Q[u].size(); ++i) {
    f[u] = max(f[u], sum[u] + query(Q[u][i].u, Q[u][i].v, u) + Q[u][i].val);
  }
  modify(u, sum[u] - f[u]);
}
inline void work(void) {
  TreeDP(1, 0);
  printf("%d", f[1]);
}
int main() {
  init();
  work();
  return 0;
}