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 <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
long long test;
long long n, m;
long long dp[(1 << 19)][19];
long long dp1[(1 << 19)];
long long load[2 * (1 << 19)];
long long cou;
long long h[(1 << 19)];
vector<long long> g[(1 << 19)];
vector<pair<pair<long long, long long>, long long>> edg[(1 << 19)];
long long pre[(1 << 19)], post[(1 << 19)];
long long diff[(1 << 19)];
long long lca(long long x, long long y) {
  if (h[x] < h[y]) {
    swap(x, y);
  }
  for (long long i = 19 - 1; i >= (0); --i) {
    if (h[x] - (1 << i) >= h[y]) {
      x = dp[x][i];
    }
  }
  if (x == y) {
    return x;
  }
  for (long long i = 19 - 1; i >= (0); --i) {
    if (dp[x][i] != dp[y][i]) {
      x = dp[x][i];
      y = dp[y][i];
    }
  }
  return dp[x][0];
}
void dfs(long long v, long long p) {
  h[v] = h[p] + 1;
  dp[v][0] = p;
  pre[v] = ++cou;
  for (auto it : g[v]) {
    dfs(it, v);
  }
  post[v] = cou;
  return;
}
void insert(long long l, long long r, long long x) {
  l += (1 << 19);
  r += (1 << 19);
  load[l] += x;
  if (l != r) {
    load[r] += x;
  }
  while (l / 2 != r / 2) {
    if (l % 2 == 0) {
      load[l + 1] += x;
    }
    if (r % 2 == 1) {
      load[r - 1] += x;
    }
    l /= 2;
    r /= 2;
  }
  return;
}
long long query(long long x) {
  x += (1 << 19);
  long long res = 0;
  while (x >= 1) {
    res += load[x];
    x /= 2;
  }
  return res;
}
void dfs1(long long v) {
  for (auto it : g[v]) {
    dfs1(it);
    diff[v] += diff[it];
    dp1[v] += dp1[it];
  }
  dp1[v] = diff[v];
  for (auto it : edg[v]) {
    dp1[v] = max(dp1[v], it.second + diff[v] - query(pre[it.first.first]) -
                             query(pre[it.first.second]));
  }
  insert(pre[v], post[v], dp1[v] - diff[v]);
  diff[v] += dp1[v] - diff[v];
  return;
}
void solve() {
  cin >> n >> m;
  for (long long i = 2; i <= (n); ++i) {
    long long x;
    cin >> x;
    g[x].push_back(i);
  }
  dfs(1, 1);
  for (long long i = 1; i <= (19 - 1); ++i) {
    for (long long j = 1; j <= (n); ++j) {
      dp[j][i] = dp[dp[j][i - 1]][i - 1];
    }
  }
  for (long long i = 1; i <= (m); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    edg[lca(a, b)].emplace_back(make_pair(a, b), c);
  }
  dfs1(1);
  cout << dp1[1];
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}