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;
const int L = 20;
int n, pre[N][L], lvl[N];
vector<int> adj[N];
int lca(int u, int v) {
  if (lvl[u] > lvl[v]) swap(u, v);
  for (int l = (int)(L)-1; l >= ((int)0); l--)
    if (lvl[pre[v][l]] >= lvl[u]) v = pre[v][l];
  if (u == v) return u;
  for (int l = (int)(L)-1; l >= ((int)0); l--)
    if (pre[u][l] != pre[v][l]) {
      u = pre[u][l];
      v = pre[v][l];
    }
  assert(u != v);
  return pre[u][0];
}
int cum[N];
int get(int x) {
  x += 2;
  int ans = 0;
  while (x) {
    ans += cum[x];
    x -= x & (-x);
  }
  return ans;
}
void add(int x, int delta) {
  x += 2;
  while (x < N) {
    cum[x] += delta;
    x += x & (-x);
  }
}
int t = 1, d[N], f[N];
void dfs(int u) {
  d[u] = t++;
  for (int v : adj[u]) dfs(v);
  f[u] = t;
}
struct edge {
  int u, v, c;
};
vector<edge> path[N];
int dp[N];
void dpDfs(int u) {
  int ans = 0;
  for (int v : adj[u]) {
    dpDfs(v);
    ans += dp[v];
  }
  int cost = 0;
  for (auto p : path[u]) {
    int add = p.c - get(d[p.u]) - get(d[p.v]);
    cost = max(cost, add);
  }
  dp[u] = ans + cost;
  add(d[u], cost);
  add(f[u], -cost);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n - 1); i++) {
    cin >> pre[i + 2][0];
    lvl[i + 2] = 1 + lvl[pre[i + 2][0]];
    adj[pre[i + 2][0]].push_back(i + 2);
  }
  pre[1][0] = 1;
  for (int l = 0; l < (int)(L - 1); l++)
    for (int u = 0; u < (int)(n + 1); u++) pre[u][l + 1] = pre[pre[u][l]][l];
  dfs(1);
  while (m--) {
    int u, v, c;
    cin >> u >> v >> c;
    int p = lca(u, v);
    path[p].push_back((edge){u, v, c});
  }
  dpDfs(1);
  cout << dp[1] << endl;
  return 0;
}