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 int INF = 2e9;
const double eps = 1e-12;
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
const int N = 200010;
int n, m;
int head[N], nxt[N << 1], to[N << 1], lst = 0;
inline void adde(int x, int y) {
  nxt[++lst] = head[x];
  to[lst] = y;
  head[x] = lst;
}
int fa[N], dep[N];
int sz[N], top[N], son[N];
void Build(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa[u]) {
      int v = to[i];
      fa[v] = u;
      dep[v] = dep[u] + 1;
      Build(v);
      if (!son[u] || sz[son[u]] < sz[v]) son[u] = v;
    }
}
void GetTop(int u) {
  if (son[u]) {
    top[son[u]] = top[u];
    GetTop(son[u]);
  }
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa[u] && to[i] != son[u]) {
      int v = to[i];
      top[v] = v;
      GetTop(v);
    }
}
inline int Lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
struct PATH {
  int x, y, c;
  inline void in() {
    read(x);
    read(y);
    read(c);
  }
  inline void print() { printf("%d %d %d\n", x, y, c); }
};
vector<PATH> p[N];
int f[N], val[N], sum[N];
inline int Query(int x, int y) {
  int ret = 0;
  while (top[x] != top[y]) {
    ret += sum[top[x]] - sum[son[x]];
    x = fa[top[x]];
  }
  ret += sum[y] - sum[son[x]];
  return ret;
}
void Solve(int u) {
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa[u]) Solve(to[i]), val[u] += f[to[i]];
  sum[u] = val[u] + sum[son[u]];
  f[u] = val[u];
  for (auto t : p[u]) {
    f[u] = max(f[u], t.c + Query(t.x, u) + Query(t.y, u) - val[u]);
  }
  sum[u] = val[u] - f[u] + sum[son[u]];
}
signed main() {
  read(n);
  read(m);
  for (int i = 2; i <= n; i++) {
    int x;
    read(x);
    adde(x, i);
    adde(i, x);
  }
  top[1] = dep[1] = 1;
  Build(1);
  GetTop(1);
  for (int i = 1; i <= m; i++) {
    PATH tmp;
    tmp.in();
    p[Lca(tmp.x, tmp.y)].push_back(tmp);
  }
  Solve(1);
  printf("%d\n", f[1]);
  return 0;
}