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() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
struct Edge {
  int u, v, Next;
} G[200010];
int head[200010], tot, n, m;
int h[200010], Top[200010], Fa[200010], Size[200010], mx[200010];
int num[200010], mp[200010], cnt, C[200010], f[200010];
vector<pair<pair<int, int>, int> > op[200010];
inline void add(int u, int v) {
  G[++tot] = (Edge){u, v, head[u]};
  head[u] = tot;
}
inline void Add(int x, int y) {
  for (; x <= n; x += (x & -x)) {
    C[x] += y;
  }
}
inline int Query(int x) {
  int ret = 0;
  for (; x > 0; x -= (x & -x)) {
    ret += C[x];
  }
  return ret;
}
inline int ask(int x, int y) { return Query(y) - Query(x - 1); }
inline void dfs(int x, int f, int hei) {
  h[x] = hei;
  Fa[x] = f;
  Size[x] = 1;
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dfs(G[i].v, x, hei + 1);
    Size[x] += Size[G[i].v];
    if (Size[G[i].v] > Size[mx[x]]) mx[x] = G[i].v;
  }
}
inline void dfs2(int x) {
  mp[num[x] = ++cnt] = x;
  if (mx[x]) Top[mx[x]] = Top[x], dfs2(mx[x]);
  for (int i = head[x]; i != -1; i = G[i].Next) {
    if (G[i].v == mx[x]) continue;
    Top[G[i].v] = G[i].v;
    dfs2(G[i].v);
  }
}
inline int lca(int x, int y) {
  while (Top[x] != Top[y]) {
    if (h[Top[x]] < h[Top[y]]) swap(x, y);
    x = Fa[Top[x]];
  }
  return h[x] < h[y] ? x : y;
}
inline int query(int x, int y) {
  if (h[Top[x]] < h[Top[y]]) return 0;
  int ret = 0;
  while (Top[x] != Top[y]) {
    ret += ask(num[Top[x]], num[x]) + f[mx[x]] - f[Top[x]];
    x = Fa[Top[x]];
  }
  ret += ask(num[y], num[x]) + f[mx[x]];
  return ret;
}
inline int last(int x, int y) {
  while (Top[x] != Top[y]) {
    if (Fa[Top[x]] == y) return Top[x];
    x = Fa[Top[x]];
  }
  return mp[num[y] + 1];
}
inline void dp(int x) {
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dp(G[i].v);
    f[x] += f[G[i].v];
  }
  Add(num[x], f[x] - f[mx[x]]);
  for (int i = 0; i < op[x].size(); i++) {
    int u = last(op[x][i].first.first, x);
    int res = query(op[x][i].first.first, u) + query(op[x][i].first.second, x);
    res -= f[u] - op[x][i].second;
    f[x] = max(f[x], res);
  }
}
int main() {
  n = read(), m = read();
  Top[1] = 1;
  memset(head, -1, sizeof(head));
  for (int i = (2); i <= (n); i++) {
    int p = read();
    add(p, i);
  }
  dfs(1, 0, 1);
  dfs2(1);
  for (int i = (1); i <= (m); i++) {
    pair<pair<int, int>, int> t;
    t.first.first = read();
    t.first.second = read();
    t.second = read();
    if (h[t.first.first] < h[t.first.second])
      swap(t.first.first, t.first.second);
    op[lca(t.first.first, t.first.second)].push_back(t);
  }
  dp(1);
  cout << f[1] << endl;
  return 0;
}