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;
template <typename T>
inline void read(T &x) {
  char ch;
  while ((ch = getchar()), (ch < '0' || ch > '9'))
    ;
  x = ch - '0';
  while ((ch = getchar()), (ch >= '0' && ch <= '9')) x = x * 10 + (ch - '0');
}
const int MAXN = 200010;
const int MAXLOG = 18;
int N, M;
struct BIT {
  long long C[MAXN];
  inline void _add(int id, long long x) {
    while (id <= N) {
      C[id] += x;
      id += ((id) & -(id));
    }
  }
  inline long long _sum(int id) {
    long long ans = 0;
    while (id >= 1) {
      ans += C[id];
      id -= ((id) & -(id));
    }
    return ans;
  }
  inline void add(int l, int r, long long x) {
    _add(l, x);
    _add(r + 1, -x);
  }
  inline long long query(int id) { return _sum(id); }
} BG, BF;
namespace tree {
int fa[MAXN][MAXLOG], enter[MAXN], leave[MAXN], dep[MAXN], clock = 1;
int head[MAXN], next[2 * MAXN], tail[2 * MAXN], id = 1, maxlog;
struct item {
  int u, v, x;
};
vector<item> line[MAXN];
inline void link(int u, int v) {
  next[id] = head[u];
  tail[id] = v;
  head[u] = id++;
}
void dfs(int u) {
  int i, v;
  enter[u] = clock++;
  for (i = head[u]; i; i = next[i]) {
    v = tail[i];
    dep[v] = dep[u] + 1;
    dfs(v);
  }
  leave[u] = clock - 1;
}
inline void prelude() {
  int i, u;
  for (maxlog = 1; (1 << maxlog) <= N; maxlog++)
    ;
  maxlog--;
  for (i = 1; i <= maxlog; i++) {
    bool ok = 0;
    for (u = 1; u <= N; u++) fa[u][i] = fa[fa[u][i - 1]][i - 1], ok |= fa[u][i];
    if (!ok) {
      maxlog = i - 1;
      break;
    }
  }
}
inline int lca(int x, int y) {
  int i;
  if (dep[x] > dep[y]) swap(x, y);
  for (i = maxlog; i >= 0; i--)
    if (fa[y][i] && dep[fa[y][i]] >= dep[x]) y = fa[y][i];
  if (x != y) {
    for (i = maxlog; i >= 0; i--)
      if (fa[x][i] && fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return fa[x][0];
  }
  return x;
}
long long dp[MAXN], g[MAXN];
void solve(int u) {
  int i, v;
  item x;
  for (i = head[u]; i; i = next[i]) {
    v = tail[i];
    solve(v);
    g[u] += dp[v];
  }
  dp[u] = g[u];
  for (i = 0; i < line[u].size(); i++) {
    x = line[u][i];
    dp[u] =
        max(dp[u], x.x + g[u] + BG.query(enter[x.u]) + BG.query(enter[x.v]) -
                       BF.query(enter[x.u]) - BF.query(enter[x.v]));
  }
  BG.add(enter[u], leave[u], g[u]);
  BF.add(enter[u], leave[u], dp[u]);
}
}  // namespace tree
int main() {
  using namespace tree;
  int i, u, v, x;
  read(N);
  read(M);
  for (i = 2; i <= N; i++) read(fa[i][0]), link(fa[i][0], i);
  prelude();
  dfs(1);
  for (i = 1; i <= M; i++)
    read(u), read(v), read(x), line[lca(u, v)].push_back((item){u, v, x});
  solve(1);
  printf("%I64d", dp[1]);
}