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;
const int N = 200000 + 7;
const int M = 20;
const int multipleTest = 0;
class FenWickTree {
 public:
  static const int MAXN = N;
  long long L[MAXN];
  void update(int x, long long val) {
    for (int t = x; t < MAXN; t += t & -t) L[t] += val;
  }
  long long get(int x) {
    long long res = 0;
    for (int t = x; t > 0; t -= t & -t) {
      res += L[t];
    }
    return res;
  }
  long long getVal(int u, int v) { return get(v) - get(u - 1); }
} fenwickTree;
vector<int> adj[N];
int pa[N][20];
int depth[N];
int n, m;
int k = 0;
int f[N], nxt[N], root[N], pos[N];
vector<int> ver[N];
void dfs(int u, int r) {
  pa[u][0] = r;
  for (int j = 1; j < 20; ++j) {
    if (pa[u][j - 1] == -1)
      pa[u][j] = -1;
    else
      pa[u][j] = pa[pa[u][j - 1]][j - 1];
  }
  f[u] = 1;
  ver[depth[u]].push_back(u);
  for (int v : adj[u]) {
    if (v != r) {
      depth[v] = depth[u] + 1;
      dfs(v, u);
      f[u] += f[v];
      if (nxt[u] == 0 || f[nxt[u]] < f[v]) {
        nxt[u] = v;
      }
    }
  }
}
int LCA(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  while (depth[u] > depth[v]) {
    int k = log2(depth[u] - depth[v]);
    u = pa[u][k];
  }
  if (u == v) return u;
  for (int j = 19; j >= 0; --j) {
    if (pa[u][j] != -1 && pa[v][j] != pa[u][j]) {
      u = pa[u][j];
      v = pa[v][j];
    }
  }
  return pa[u][0];
}
void buildHLD() {
  for (int i = 0; i < n; ++i) {
    for (int u : ver[i]) {
      if (pos[u] == 0) {
        root[u] = u;
        pos[u] = ++k;
        int v = u;
        while (nxt[v]) {
          v = nxt[v];
          pos[v] = ++k;
          root[v] = u;
        }
      }
    }
  }
}
int getPa(int u, int depth) {
  for (int j = M - 1; j >= 0; --j)
    if (depth & (1 << j)) u = pa[u][j];
  return u;
}
pair<pair<int, int>, int> edge[N];
long long dp[N];
long long sum[N];
vector<pair<int, int> > rr[N];
long long getCost(int u, int d) {
  long long res = dp[nxt[u]];
  while (u != -1 && depth[u] >= d) {
    int r = root[u];
    if (depth[r] >= d) {
      res += fenwickTree.getVal(pos[r], pos[u]);
      if (pa[r][0] != -1 && depth[r] > d) res += -dp[r] + dp[nxt[pa[r][0]]];
      u = pa[r][0];
    } else {
      res += fenwickTree.getVal(pos[u] + (d - depth[u]), pos[u]);
      break;
    }
  }
  return res;
}
void solve() {
  cin >> n >> m;
  for (int i = 2; i <= n; ++i) {
    int u;
    scanf("%d", &u);
    adj[u].push_back(i);
  }
  dfs(1, -1);
  buildHLD();
  for (int j = (0), _b = (m); j < _b; ++j) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    edge[j] = make_pair(make_pair(u, v), c);
    int r = LCA(u, v);
    rr[r].push_back(make_pair(j, c));
  }
  for (int j = n - 1; j >= 0; --j) {
    for (int u : ver[j]) {
      sum[u] = 0;
      for (int v : adj[u]) sum[u] += dp[v];
      dp[u] = sum[u];
      for (pair<int, int>& tmp : rr[u]) {
        int sc1 = edge[tmp.first].first.first;
        int sc2 = edge[tmp.first].first.second;
        int cost = tmp.second;
        if (sc1 != u && sc2 != u) {
          dp[u] = max(dp[u], sum[u] + getCost(sc1, depth[u] + 1) +
                                 getCost(sc2, depth[u] + 1) + cost -
                                 dp[getPa(sc1, depth[sc1] - depth[u] - 1)] -
                                 dp[getPa(sc2, depth[sc2] - depth[u] - 1)]);
        } else {
          if (sc2 == u) swap(sc1, sc2);
          dp[u] = max(dp[u], sum[u] + getCost(sc2, depth[u] + 1) + cost -
                                 dp[getPa(sc2, depth[sc2] - depth[u] - 1)]);
        }
      }
      fenwickTree.update(pos[u], sum[u] - dp[nxt[u]]);
    }
  }
  cout << dp[1] << '\n';
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}