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 N = 2e5 + 10;
int n, m, dp[N], sm[N], sdp[N];
int tot, fi[N], a[N], ne[N];
struct Mt {
  int x, y, v;
};
vector<Mt> g[N];
inline void read(int &x) {
  char c = getchar();
  x = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
}
inline void add(int x, int y) {
  a[++tot] = y;
  ne[tot] = fi[x];
  fi[x] = tot;
}
int si[N], ms[N], de[N], tp[N], fa[N];
inline void get_ms(int x, int pa) {
  si[x] = 1;
  fa[x] = pa;
  de[x] = de[pa] + 1;
  for (int i = fi[x]; i; i = ne[i])
    get_ms(a[i], x), si[x] += si[a[i]],
        ms[x] = si[a[i]] > si[ms[x]] ? a[i] : ms[x];
}
inline void get_tp(int x, int top) {
  tp[x] = top;
  if (ms[x]) get_tp(ms[x], top);
  for (int i = fi[x]; i; i = ne[i])
    if (a[i] != ms[x]) get_tp(a[i], a[i]);
}
inline int get_lca(int x, int y) {
  while (tp[x] != tp[y])
    if (de[tp[x]] > de[tp[y]])
      x = fa[tp[x]];
    else
      y = fa[tp[y]];
  return de[x] > de[y] ? y : x;
}
inline int jp(int x, int o) {
  int ans = 0;
  while (tp[x] != tp[o])
    ans += (sm[tp[x]] - sm[ms[x]]) - (sdp[tp[x]] - sdp[ms[x]]), x = fa[tp[x]];
  return ans + (sm[o] - sm[ms[x]]) - (sdp[ms[o]] - sdp[ms[x]]);
}
inline void solve(int x) {
  for (int i = fi[x]; i; i = ne[i]) solve(a[i]), sm[x] += dp[a[i]];
  dp[x] = sm[x];
  sm[x] += sm[ms[x]];
  for (vector<Mt>::iterator it = g[x].begin(); it != g[x].end(); ++it)
    dp[x] = max(dp[x], jp(it->x, x) + jp(it->y, x) - sm[x] + sm[ms[x]] + it->v);
  sdp[x] = sdp[ms[x]] + dp[x];
}
int main() {
  read(n);
  read(m);
  int x, y, z;
  for (int i = 2; i <= n; ++i) read(x), add(x, i);
  get_ms(1, 0);
  get_tp(1, 1);
  for (int i = 1; i <= m; ++i) {
    read(x);
    read(y);
    read(z);
    g[get_lca(x, y)].push_back((Mt){x, y, z});
  }
  solve(1);
  printf("%d\n", dp[1]);
  return 0;
}