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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 2e5 + 100, T = 1100, OO = 1e9 + 7, M = 1e9 + 7, P = 6151,
                SQ = 360, lg = 18;
long long pr[N][lg + 5], h[N], st[N], fn[N], nxt = 1, dp[N], dk[N], fen[N],
                                             l[N], r[N], vl[N], n, m;
vector<long long> v[N], id[N];
void dfs(long long x, long long y) {
  pr[x][0] = y;
  h[x] = h[y] + 1;
  st[x] = nxt++;
  for (long long i = 1; i < lg; i++) pr[x][i] = pr[pr[x][i - 1]][i - 1];
  for (auto u : v[x])
    if (u != y) dfs(u, x);
  fn[x] = nxt;
}
long long Lca(long long x, long long y) {
  if (h[x] < h[y]) swap(x, y);
  for (long long i = lg - 1; i >= 0; i--)
    if (h[x] - (1 << i) >= h[y]) x = pr[x][i];
  if (x == y) return x;
  for (long long i = lg - 1; i >= 0; i--)
    if (pr[x][i] != pr[y][i]) x = pr[x][i], y = pr[y][i];
  return pr[x][0];
}
long long fget(long long x) {
  long long cnt = 0;
  for (; x; x -= (x & -x)) cnt += fen[x];
  return cnt;
}
void upd(long long x, long long y) {
  for (; x <= nxt; x += (x & -x)) fen[x] += y;
}
long long get(long long x, long long y) {
  for (auto u : v[x])
    if (u != y) dk[x] += get(u, x);
  dp[x] = dk[x];
  for (auto u : id[x])
    dp[x] = max(dp[x], dk[x] + fget(st[l[u]]) + fget(st[r[u]]) + vl[u]);
  upd(st[x], dk[x] - dp[x]);
  upd(fn[x], -1 * (dk[x] - dp[x]));
  return dp[x];
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    v[x].push_back(i);
  }
  dfs(1, 0);
  for (long long i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> vl[i];
    id[Lca(l[i], r[i])].push_back(i);
  }
  cout << get(1, 0) << endl;
  return 0;
}