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 long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 2e5 + 5;
struct SegmentTree {
  int sum[MAXN << 2], tag[MAXN << 2];
  void pushDown(int p) {
    if (tag[p] != 0) {
      sum[p * 2] += tag[p];
      tag[p * 2] += tag[p];
      sum[p * 2 + 1] += tag[p];
      tag[p * 2 + 1] += tag[p];
      tag[p] = 0;
    }
  }
  void pushUp(int p) { sum[p] = sum[p * 2] + sum[p * 2 + 1]; }
  void modify(int p, int tl, int tr, int ql, int qr, int x) {
    if (ql <= tl && qr >= tr) {
      sum[p] += x;
      tag[p] += x;
      return;
    }
    pushDown(p);
    int mid = (tl + tr) >> 1;
    if (ql <= mid) modify(p * 2, tl, mid, ql, qr, x);
    if (qr > mid) modify(p * 2 + 1, mid + 1, tr, ql, qr, x);
    pushUp(p);
  }
  int query(int p, int tl, int tr, int ql, int qr) {
    if (ql <= tl && qr >= tr) return sum[p];
    pushDown(p);
    int mid = (tl + tr) >> 1, res = 0;
    if (ql <= mid) res += query(p * 2, tl, mid, ql, qr);
    if (qr > mid) res += query(p * 2 + 1, mid + 1, tr, ql, qr);
    return res;
  }
  SegmentTree() {}
} F, G;
struct EDGE {
  int next, to;
} edge[MAXN << 1];
int head[MAXN], tot;
struct node {
  int u, v, c;
  node(int uu, int vv, int cc) {
    u = uu;
    v = vv;
    c = cc;
  }
};
vector<node> p[MAXN];
int n, m, f[MAXN], g[MAXN];
struct TREE {
  void add(int u, int v) {
    edge[++tot].next = head[u];
    edge[tot].to = v;
    head[u] = tot;
  }
  int fa[MAXN], dep[MAXN], sz[MAXN], son[MAXN];
  void dfs1(int u) {
    dep[u] = dep[fa[u]] + 1;
    sz[u] = 1;
    for (int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      fa[v] = u;
      dfs1(v);
      sz[u] += sz[v];
      if (sz[v] > sz[son[u]]) son[u] = v;
    }
  }
  int top[MAXN], dfn[MAXN], cnt;
  void dfs2(int u, int tp) {
    dfn[u] = ++cnt;
    top[u] = tp;
    if (son[u]) dfs2(son[u], tp);
    for (int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (v == son[u]) continue;
      dfs2(v, v);
    }
  }
  void changeF(int u, int x) { F.modify(1, 1, n, dfn[u], dfn[u], x); }
  void changeG(int u, int x) { G.modify(1, 1, n, dfn[u], dfn[u], x); }
  int get_sumF(int u, int v) {
    int res = 0;
    while (top[u] != top[v]) {
      if (dep[top[u]] < dep[top[v]]) swap(u, v);
      res += F.query(1, 1, n, dfn[top[u]], dfn[u]);
      u = fa[top[u]];
    }
    if (dfn[u] > dfn[v]) swap(u, v);
    res += F.query(1, 1, n, dfn[u], dfn[v]);
    return res;
  }
  int get_sumG(int u, int v) {
    int res = 0;
    while (top[u] != top[v]) {
      if (dep[top[u]] < dep[top[v]]) swap(u, v);
      res += G.query(1, 1, n, dfn[top[u]], dfn[u]);
      u = fa[top[u]];
    }
    if (dfn[u] > dfn[v]) swap(u, v);
    res += G.query(1, 1, n, dfn[u], dfn[v]);
    return res;
  }
  int get_lca(int u, int v) {
    while (top[u] != top[v]) {
      if (dep[top[u]] < dep[top[v]]) swap(u, v);
      u = fa[top[u]];
    }
    return dfn[u] < dfn[v] ? u : v;
  }
  TREE() { tot = cnt = 0; }
} T;
void dfs(int u) {
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    dfs(v);
    g[u] += f[v];
  }
  f[u] = g[u];
  T.changeG(u, g[u]);
  for (int i = 0; i < p[u].size(); ++i) {
    f[u] = max(f[u], T.get_sumG(p[u][i].u, p[u][i].v) -
                         T.get_sumF(p[u][i].u, p[u][i].v) + p[u][i].c);
  }
  T.changeF(u, f[u]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  n = read();
  m = read();
  for (int i = 2; i <= n; ++i) T.add(read(), i);
  T.dfs1(1);
  T.dfs2(1, 1);
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read(), c = read();
    p[T.get_lca(u, v)].push_back(node(u, v, c));
  }
  dfs(1);
  cout << f[1] << endl;
  return 0;
}