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 maxn = 201000, MAXD = 18;
int n, m, ans, stamp, l[maxn], r[maxn], f[maxn][MAXD + 1], dep[maxn];
int g[maxn], gg[maxn];
long long tree[maxn];
struct edge {
  int u, v, w;
};
vector<int> G[maxn];
vector<edge> P[maxn];
void dfs(int u) {
  l[u] = ++stamp;
  dep[u] = dep[f[u][0]] + 1;
  for (int i = 1; i <= MAXD; ++i) f[u][i] = f[f[u][i - 1]][i - 1];
  for (auto v : G[u]) dfs(v);
  r[u] = stamp;
}
inline int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = MAXD; i >= 0; --i)
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = MAXD; i >= 0; --i)
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  return f[u][0];
}
inline void modify(int x, int delta) {
  while (x <= n) {
    tree[x] += delta;
    x += x & (-x);
  }
}
inline int query(int x) {
  long long ret = 0;
  while (x) {
    ret += tree[x];
    x -= x & (-x);
  }
  return ret;
}
inline int getfa(int u, int d) {
  for (int i = MAXD; i >= 0; --i)
    if (d >= (1 << i)) {
      d ^= 1 << i;
      u = f[u][i];
    }
  return u;
}
void solve(int u) {
  for (auto v : G[u]) {
    solve(v);
    gg[u] += g[v];
  }
  g[u] = gg[u];
  for (auto item : P[u]) {
    if (item.v == u) swap(item.u, item.v);
    int f1 = getfa(item.u, dep[item.u] - dep[u] - 1),
        f2 = getfa(item.v, dep[item.v] - dep[u] - 1);
    if (item.u == u) {
      g[u] =
          max(g[u], (gg[u] - g[f2]) + query(l[item.v]) + gg[item.v] + item.w);
    } else {
      g[u] = max(g[u], (gg[u] - g[f1] - g[f2]) + query(l[item.u]) + gg[item.u] +
                           query(l[item.v]) + gg[item.v] + item.w);
    }
  }
  for (auto v : G[u]) {
    modify(l[v], gg[u] - g[v]);
    modify(r[v] + 1, -(gg[u] - g[v]));
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    G[i].clear();
    P[i].clear();
  }
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
    f[i][0] = p;
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) tree[i] = 0;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    P[getlca(u, v)].push_back((edge){u, v, w});
  }
  solve(1);
  printf("%d\n", g[1]);
}