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>
#pragma GCC diagnostic ignored "-Wunused-result"
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f\n", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
template <class T>
inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
struct BIT {
  int n;
  vector<T> dat;
  void init(int _n) {
    n = _n;
    dat.clear();
    dat.resize(n + 1);
  }
  template <bool ask_range>
  void init(int _n, T a[]) {
    init(_n);
    for (int i = 1; i <= n; i++) {
      dat[i] += ask_range ? a[i] : a[i] - a[i - 1];
      int j = i + (i & -i);
      if (j <= n) dat[j] += dat[i];
    }
  }
  void add(int x, T v) {
    for (int i = x; i <= n; i += i & -i) dat[i] += v;
  }
  T ask(int x) {
    T s = T();
    for (int i = x; i; i -= i & -i) s += dat[i];
    return s;
  }
  void add(int l, int r, T v) {
    add(l, v);
    if (r + 1 <= n) add(r + 1, -v);
  }
  T ask(int l, int r) { return ask(r) - ask(l - 1); }
};
constexpr int lg2(int x) { return 31 - __builtin_clz(x); }
const int N = 2e5 + 10;
const int M = 2e5 + 10;
const int LGN = lg2(N) + 1;
struct Q {
  int a, b, c;
} q[M];
int n, m;
vector<int> e[N];
void input() {
  R(n, m);
  for (int i = (2); i <= int(n); i++) {
    int x;
    R(x);
    e[x].push_back(i);
  }
  for (int i = 0; i < int(m); i++) R(q[i].a, q[i].b, q[i].c);
}
int dep[N], fa[LGN][N], dt[N], ot[N], ts;
void dfs(int p, int f, int lv) {
  dep[p] = lv;
  fa[0][p] = f;
  dt[p] = ++ts;
  for (int i : e[p])
    if (i != f) dfs(i, p, lv + 1);
  ot[p] = ts;
}
int lgn;
void lca_build() {
  for (int i = 0; i < lgn; i++) {
    for (int j = 1; j <= n; j++) {
      fa[i + 1][j] = fa[i][fa[i][j]];
    }
  }
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  int d = dep[b] - dep[a];
  int l = lg2(dep[b]);
  for (int i = 0; i <= l; i++) {
    if ((d >> i) & 1) b = fa[i][b];
  }
  if (a == b) return a;
  for (int i = lg2(dep[a]); i >= 0; i--) {
    if (fa[i][a] != fa[i][b]) {
      a = fa[i][a];
      b = fa[i][b];
    }
  }
  return fa[0][a];
}
vector<int> vq[N];
void build() {
  dfs(1, 0, 1);
  lgn = lg2(n);
  lca_build();
  for (int i = 0; i < int(m); i++) {
    int p = lca(q[i].a, q[i].b);
    vq[p].push_back(i);
  }
}
int64_t dp[N];
BIT<int64_t> b1, b2;
int64_t shik(int a, int b, int c) {
  int d = fa[0][c];
  int64_t s = 0;
  int64_t sa1 = b1.ask(dt[a]);
  int64_t sb1 = b1.ask(dt[b]);
  int64_t sc1 = b1.ask(dt[c]);
  int64_t sa2 = b2.ask(dt[a]);
  int64_t sb2 = b2.ask(dt[b]);
  int64_t sc2 = b2.ask(dt[c]);
  int64_t sd2 = b2.ask(dt[d]);
  s += sa2 + sb2 - sc2 - sd2;
  s -= sa1 + sb1 - 2 * sc1;
  return s;
}
void go(int p) {
  for (int i : e[p]) go(i);
  int64_t mx = 0;
  {
    int64_t s = 0;
    for (int i : e[p]) s += dp[i];
    chkmax(mx, s);
  }
  for (int i : vq[p]) {
    int64_t now = shik(q[i].a, q[i].b, p) + q[i].c;
    chkmax(mx, now);
  }
  b1.add(dt[p], ot[p], mx);
  int f = fa[0][p];
  if (f != 0) b2.add(dt[f], ot[f], mx);
  dp[p] = mx;
}
void solve() {
  b1.init(n);
  b2.init(n);
  go(1);
  W(dp[1]);
}
int main() {
  input();
  build();
  solve();
  return 0;
}