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;
inline int read() {
  int res = 0;
  int neg;
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9' || ch == '-') {
      if (ch == '-')
        neg = -1;
      else
        neg = 1, res = ch - '0';
      break;
    }
  }
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9')
      res *= 10, res += ch - '0';
    else
      break;
  }
  return res * neg;
}
const int maxn = 510020;
const int maxm = 10000020;
const int MOd = 1e9 + 7;
const int K = 200;
int dad[maxn][20], der[maxn], a, b;
bool H[maxn];
int heavy[maxn];
int beg[maxn], en[maxn], cnt;
int dn[maxn];
int segment[maxn], n;
vector<int> w[maxn];
vector<pair<pair<int, int>, int> > v[maxn];
int dfs(int n, int back, int s) {
  int ret = 1;
  dad[n][0] = back;
  der[n] = s;
  int h = 0, maxi = 0;
  for (int i = 1; (1 << i) <= s; i++) dad[n][i] = dad[dad[n][i - 1]][i - 1];
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i] != back) {
      int t = dfs(w[n][i], n, s + 1);
      if (t > maxi) maxi = t, h = i;
      ret += t;
    }
  if (w[n].size()) swap(w[n][0], w[n][h]), H[w[n][0]] = 1;
  return ret;
}
int lca(int x, int y) {
  if (der[x] < der[y]) swap(x, y);
  for (int k = 18; k >= 0; k--)
    if ((1 << k) <= der[x] && der[dad[x][k]] > der[y]) x = dad[x][k];
  if (der[x] != der[y]) x = dad[x][0];
  for (int k = 18; k >= 0; k--)
    if ((1 << k) <= der[x] && dad[x][k] != dad[y][k])
      x = dad[x][k], y = dad[y][k];
  if (x != y) x = dad[x][0];
  return x;
}
void dfs2(int n, int back, int last) {
  beg[n] = ++cnt;
  if (H[n] && !H[back]) last = n;
  if (H[n]) heavy[n] = last;
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i] != back) {
      dfs2(w[n][i], n, last);
    }
  en[n] = cnt;
}
void up(int x, int y) {
  for (int k = n + x - 1; k; k >>= 1) segment[k] += y;
}
int find(int l, int r) {
  int ret = 0;
  for (l += n - 1, r += n - 1; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) ret += segment[l];
    if (~r & 1) ret += segment[r];
  }
  return ret;
}
int add(int x, int y) {
  int ret = 0;
  while (der[x] > der[y]) {
    if (H[x]) {
      if (der[heavy[x]] > der[y]) {
        ret += find(beg[heavy[x]], beg[x]);
        x = dad[heavy[x]][0];
      } else {
        ret += find(beg[y] + 1, beg[x]);
        break;
      }
    } else {
      ret += segment[beg[x] + n - 1];
      x = dad[x][0];
    }
  }
  assert(ret <= 0);
  return ret;
}
int f(int n) {
  int chi = 0;
  for (int i = 0; i < w[n].size(); i++) {
    chi += f(w[n][i]);
  }
  dn[n] = chi;
  for (int i = 0; i < v[n].size(); i++) {
    int t = v[n][i].second;
    dn[n] = max(dn[n], (chi + add(v[n][i].first.first, n) +
                        add(v[n][i].first.second, n) + t));
  }
  up(beg[n], chi - dn[n]);
  return dn[n];
}
int main() {
  scanf("%d %d", &a, &b);
  for (int i = 2, j; i <= a; i++) {
    scanf("%d", &j);
    w[j].push_back(i);
  }
  n = 1;
  while (n < a) n <<= 1;
  dfs(1, 0, 0);
  dfs2(1, 0, 0);
  for (int i = 1, j, k, t; i <= b; i++) {
    scanf("%d %d %d", &j, &k, &t);
    int x = lca(j, k);
    v[x].push_back(pair<pair<int, int>, int>(pair<int, int>(j, k), t));
  }
  cout << f(1) << endl;
  return 0;
}