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 s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
  return s * f;
}
const int N = 2e5 + 5, LOG = 20;
struct Edge {
  int to, next;
} e[N << 1];
int head[N], ecnt;
inline void add(int u, int v) {
  e[++ecnt].next = head[u];
  head[u] = ecnt;
  e[ecnt].to = v;
}
int n, m;
inline int lowbit(int x) { return x & (-x); }
struct BIT {
  int tr[N];
  inline void add(int pos, int val) {
    for (; pos <= n; pos += lowbit(pos)) tr[pos] += val;
  }
  inline int query(int pos) {
    int ret = 0;
    for (; pos; pos -= lowbit(pos)) ret += tr[pos];
    return ret;
  }
  inline void modify(int l, int r, int val) {
    add(l, val);
    add(r + 1, -val);
  }
} T;
int size[N], f[N], fa[N][LOG], dep[N], Log2[N], dfn[N], inde;
inline void init() {
  for (int i = 1; i <= n; ++i) Log2[i] = Log2[i - 1] + (1 << Log2[i - 1] == i);
}
void dfs1(int u, int fat) {
  dep[u] = dep[fat] + 1;
  fa[u][0] = fat;
  size[u] = 1;
  dfn[u] = ++inde;
  for (int i = 1; i < Log2[dep[u]]; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = head[u], v; i; i = e[i].next) {
    v = e[i].to;
    dfs1(v, u);
    size[u] += size[v];
  }
}
inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[y]) x = fa[x][Log2[dep[x] - dep[y]] - 1];
  if (x == y) return x;
  for (int i = Log2[dep[x]] - 1; i >= 0; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
struct Query {
  int x, y, lca, w;
  inline void build() {
    x = read(), y = read();
    lca = LCA(x, y);
    w = read();
  }
} q[N];
vector<Query> vec[N];
void dfs2(int u) {
  int sum = 0;
  for (int i = head[u], v; i; i = e[i].next) {
    v = e[i].to;
    dfs2(v);
    sum += f[v];
  }
  f[u] = sum;
  for (int i = 0; i < vec[u].size(); ++i) {
    Query x = vec[u][i];
    f[u] = max(f[u], sum + T.query(dfn[x.x]) + T.query(dfn[x.y]) + x.w);
  }
  T.modify(dfn[u], dfn[u] + size[u] - 1, sum - f[u]);
}
int main() {
  n = read(), m = read();
  for (int i = 2, fat; i <= n; ++i) {
    fat = read();
    add(fat, i);
  }
  init();
  dfs1(1, 0);
  for (int i = 1; i <= m; ++i) {
    q[i].build();
    vec[q[i].lca].push_back(q[i]);
  }
  dfs2(1);
  printf("%d\n", f[1]);
  return 0;
}