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,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.2")
using namespace std;
inline void opting() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
long long inp() {
  long long x;
  cin >> x;
  return x;
}
void make_unique(vector<long long> &vec, bool sorted = false) {
  if (!sorted) sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
void file_edit(bool reader = true, bool writer = false) {
  if (reader) freopen("Test_input.txt", "r", stdin);
  if (writer) freopen("Test_output.txt", "w", stdout);
}
const int SQRT = 65, lg = 18 + 2, inlim = 2147483647;
const int maxn = 2e5 + 20, delta = 1e9 + 7, inf = 1e9 + 420;
char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
const int N = 200010;
const int M = 19;
int h[N], nx[N << 1], t[N << 1], num;
int c[N];
int F[N][M];
int d[N], L[N], R[N], f[N], cnt;
int u[N], v[N], w[N];
vector<int> a[N];
int k, n, m, Ans;
void Add(int x, int y) {
  t[++num] = y;
  nx[num] = h[x];
  h[x] = num;
}
void Dfs(int x) {
  d[x] = d[F[x][0]] + 1;
  for (int i = 1; i < M; i++) F[x][i] = F[F[x][i - 1]][i - 1];
  L[x] = ++cnt;
  for (int i = h[x]; i; i = nx[i]) Dfs(t[i]);
  R[x] = cnt;
}
int Lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = M - 1; ~i; i--)
    if (d[F[x][i]] >= d[y]) x = F[x][i];
  if (x == y) return x;
  for (int i = M - 1; ~i; i--)
    if (F[x][i] != F[y][i]) x = F[x][i], y = F[y][i];
  return F[x][0];
}
void Update(int x, int y) {
  for (; x <= n; x += x & -x) c[x] += y;
}
int Query(int x) {
  int Ans = 0;
  for (; x; x -= x & -x) Ans += c[x];
  return Ans;
}
void Up(int l, int r, int y) {
  Update(l, y);
  Update(r + 1, -y);
}
void Solve(int x) {
  int S = 0;
  for (int i = h[x]; i; i = nx[i]) {
    Solve(t[i]);
    S += f[t[i]];
  }
  f[x] = S;
  for (int i = 0; i < a[x].size(); i++) {
    int y = a[x][i];
    f[x] = max(f[x], Query(L[u[y]]) + Query(L[v[y]]) + S + w[y]);
  }
  Up(L[x], R[x], S - f[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 2; i <= n; i++) {
    cin >> F[i][0];
    Add(F[i][0], i);
  }
  Dfs(1);
  for (int i = 1; i <= m; i++)
    cin >> u[i] >> v[i] >> w[i], a[Lca(u[i], v[i])].push_back(i);
  Solve(1);
  cout << f[1] << endl;
  return 0;
}