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;
namespace FastIO {
const int S = 2000000;
char s[S], *h = s + S, *t = h;
inline char getchr(void) {
  if (h == t) {
    if (t != s + S) return -1;
    t = s + fread(s, 1, S, stdin), h = s;
  }
  return *h++;
}
inline int getint(void) throw(int) {
  char c = ' ';
  bool positive = true;
  for (; !isdigit(c); c = getchr()) {
    if (c == -1) throw(-1);
    positive ^= (c == '-');
  }
  int x = 0;
  for (; isdigit(c); c = getchr()) x = x * 10 + c - '0';
  return positive ? x : -x;
}
}  // namespace FastIO
using FastIO::getint;
const int N = 200010, M = 20;
int n, m;
struct Edge {
  int u, v, w;
} data[N];
vector<int> wait[N];
int l[N], r[N], fa[N][M], dep[N], size[N], q[N];
long long f[N], g[N];
vector<int> graph[N];
long long tr[N];
void bfs() {
  q[1] = 1, dep[1] = 1, fa[1][0] = 0;
  for (int i = 1, tail = 1; i <= tail; ++i) {
    int u = q[i];
    for (auto v : graph[u]) {
      dep[v] = dep[u] + 1, fa[v][0] = u;
      q[++tail] = v;
    }
  }
  for (int i = n; i > 0; --i) {
    int u = q[i];
    size[fa[u][0]] += ++size[u];
  }
  l[1] = 1;
  for (int i = 1; i <= n; ++i) {
    int u = q[i], now = 0;
    r[u] = l[u] + size[u] - 1;
    for (auto v : graph[u]) {
      l[v] = l[u] + now + 1;
      now += size[v];
    }
  }
}
inline int getfa(int u, int d) {
  for (int i = 0; i < M; ++i)
    if ((d >> i) & 1) u = fa[u][i];
  return u;
}
inline int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = M - 1; i >= 0; --i)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = M - 1; i >= 0; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, long long v) {
  if (x <= 0) return;
  for (; x <= n; x += lowbit(x)) tr[x] += v;
}
inline long long query(int x) {
  long long ret = 0;
  for (; x > 0; x -= lowbit(x)) ret += tr[x];
  return ret;
}
void solve() {
  bfs();
  for (int i = 1; i < M; ++i)
    for (int j = 1; j <= n; ++j) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  for (int i = 1; i <= m; ++i) wait[getlca(data[i].u, data[i].v)].push_back(i);
  for (int i = 1; i <= n; ++i) tr[i] = 0;
  for (int idx = n; idx > 0; idx--) {
    int u = q[idx];
    g[u] = 0;
    for (auto v : graph[u]) g[u] += f[v];
    f[u] = g[u];
    for (auto q : wait[u]) {
      int qu = data[q].u, qv = data[q].v, qw = data[q].w;
      if (qv == u) swap(qu, qv);
      int f1 = getfa(qu, dep[qu] - dep[u] - 1),
          f2 = getfa(qv, dep[qv] - dep[u] - 1);
      if (qu == u)
        f[u] = max(f[u], g[u] - f[f2] + query(l[qv]) + qw + g[qv]);
      else
        f[u] = max(f[u], g[u] - f[f1] - f[f2] + qw + query(l[qu]) + g[qu] +
                             query(l[qv]) + g[qv]);
    }
    for (auto v : graph[u]) {
      add(l[v], g[u] - f[v]);
      add(r[v] + 1, f[v] - g[u]);
    }
  }
  cout << f[1] << endl;
}
int main() {
  n = getint();
  m = getint();
  for (int i = 2; i <= n; ++i) {
    int p = getint();
    graph[p].push_back(i);
  }
  for (int i = 1; i <= m; ++i) {
    data[i].u = getint();
    data[i].v = getint();
    data[i].w = getint();
  }
  solve();
  return 0;
}