#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0;
  int neg;
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9' || ch == '-') {
      if (ch == '-')
        neg = -1;
      else
        neg = 1, res = ch - '0';
      break;
    }
  }
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9')
      res *= 10, res += ch - '0';
    else
      break;
  }
  return res * neg;
}
const int maxn = 510020;
const int maxm = 10000020;
const int MOd = 1e9 + 7;
const int K = 200;
int dad[maxn][20], der[maxn], a, b;
bool H[maxn];
int heavy[maxn];
int beg[maxn], en[maxn], cnt;
int dn[maxn];
int segment[maxn], n;
vector<int> w[maxn];
vector<pair<pair<int, int>, int> > v[maxn];
int dfs(int n, int back, int s) {
  int ret = 1;
  dad[n][0] = back;
  der[n] = s;
  int h = 0, maxi = 0;
  for (int i = 1; (1 << i) <= s; i++) dad[n][i] = dad[dad[n][i - 1]][i - 1];
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i] != back) {
      int t = dfs(w[n][i], n, s + 1);
      if (t > maxi) maxi = t, h = i;
      ret += t;
    }
  if (w[n].size()) swap(w[n][0], w[n][h]), H[w[n][0]] = 1;
  return ret;
}
int lca(int x, int y) {
  if (der[x] < der[y]) swap(x, y);
  for (int k = 18; k >= 0; k--)
    if ((1 << k) <= der[x] && der[dad[x][k]] > der[y]) x = dad[x][k];
  if (der[x] != der[y]) x = dad[x][0];
  for (int k = 18; k >= 0; k--)
    if ((1 << k) <= der[x] && dad[x][k] != dad[y][k])
      x = dad[x][k], y = dad[y][k];
  if (x != y) x = dad[x][0];
  return x;
}
void dfs2(int n, int back, int last) {
  beg[n] = ++cnt;
  if (H[n] && !H[back]) last = n;
  if (H[n]) heavy[n] = last;
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i] != back) {
      dfs2(w[n][i], n, last);
    }
  en[n] = cnt;
}
void up(int x, int y) {
  for (int k = n + x - 1; k; k >>= 1) segment[k] += y;
}
int find(int l, int r) {
  int ret = 0;
  for (l += n - 1, r += n - 1; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) ret += segment[l];
    if (~r & 1) ret += segment[r];
  }
  return ret;
}
int add(int x, int y) {
  int ret = 0;
  while (der[x] > der[y]) {
    if (H[x]) {
      if (der[heavy[x]] > der[y]) {
        ret += find(beg[heavy[x]], beg[x]);
        x = dad[heavy[x]][0];
      } else {
        ret += find(beg[y] + 1, beg[x]);
        break;
      }
    } else {
      ret += segment[beg[x] + n - 1];
      x = dad[x][0];
    }
  }
  assert(ret <= 0);
  return ret;
}
int f(int n) {
  int chi = 0;
  for (int i = 0; i < w[n].size(); i++) {
    chi += f(w[n][i]);
  }
  dn[n] = chi;
  for (int i = 0; i < v[n].size(); i++) {
    int t = v[n][i].second;
    dn[n] = max(dn[n], (chi + add(v[n][i].first.first, n) +
                        add(v[n][i].first.second, n) + t));
  }
  up(beg[n], chi - dn[n]);
  return dn[n];
}
int main() {
  scanf("%d %d", &a, &b);
  for (int i = 2, j; i <= a; i++) {
    scanf("%d", &j);
    w[j].push_back(i);
  }
  n = 1;
  while (n < a) n <<= 1;
  dfs(1, 0, 0);
  dfs2(1, 0, 0);
  for (int i = 1, j, k, t; i <= b; i++) {
    scanf("%d %d %d", &j, &k, &t);
    int x = lca(j, k);
    v[x].push_back(pair<pair<int, int>, int>(pair<int, int>(j, k), t));
  }
  cout << f(1) << endl;
  return 0;
}
