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++;
}
template <class T>
inline void rea(T &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}
inline int rea(char *x, int L = 'a', int R = 'z') {
  char c = nc();
  int len = 0;
  for (; c > R || c < L; c = nc())
    ;
  for (; c >= L && c <= R; x[++len] = c, c = nc())
    ;
  return len;
}
const int N = 200010, P = 1e9 + 7;
int n, m, it, L[N], R[N], dpt[N];
vector<int> s[N];
struct iedge {
  int x, y, w;
  iedge(int _x = 0, int _y = 0, int _w = 0) : x(_x), y(_y), w(_w) {}
};
vector<iedge> e[N];
int fa[N][20];
void dfs(int u) {
  L[u] = ++it;
  dpt[u] = dpt[fa[u][0]] + 1;
  for (int i = 1; i <= 18; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int v : s[u]) dfs(v);
  R[u] = it;
}
inline int lca(int x, int y) {
  if (dpt[x] < dpt[y]) swap(x, y);
  for (int i = 18; ~i; i--)
    if (dpt[fa[x][i]] >= dpt[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 18; ~i; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int f[N], b[N];
inline void Add(int x, int y) {
  for (; x <= n; x += x & -x) b[x] += y;
}
inline int Query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret += b[x];
  return ret;
}
void dp(int u) {
  for (int v : s[u]) dp(v);
  int ss = 0;
  for (int v : s[u]) ss += f[v];
  f[u] = ss;
  for (auto ed : e[u]) {
    int cur = Query(L[ed.x]) + Query(L[ed.y]) + ed.w + ss;
    f[u] = max(cur, f[u]);
  }
  Add(L[u], ss - f[u]);
  Add(R[u] + 1, f[u] - ss);
}
int main() {
  rea(n);
  rea(m);
  for (int i = 2, x; i <= n; i++) rea(x), s[x].push_back(i), fa[i][0] = x;
  dfs(1);
  for (int i = 1, x, y, w; i <= m; i++)
    rea(x), rea(y), rea(w), e[lca(x, y)].push_back({x, y, w});
  dp(1);
  printf("%d\n", f[1]);
  return 0;
}