#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
  return s * f;
}
const int N = 2e5 + 5, LOG = 20;
struct Edge {
  int to, next;
} e[N << 1];
int head[N], ecnt;
inline void add(int u, int v) {
  e[++ecnt].next = head[u];
  head[u] = ecnt;
  e[ecnt].to = v;
}
int n, m;
inline int lowbit(int x) { return x & (-x); }
struct BIT {
  int tr[N];
  inline void add(int pos, int val) {
    for (; pos <= n; pos += lowbit(pos)) tr[pos] += val;
  }
  inline int query(int pos) {
    int ret = 0;
    for (; pos; pos -= lowbit(pos)) ret += tr[pos];
    return ret;
  }
  inline void modify(int l, int r, int val) {
    add(l, val);
    add(r + 1, -val);
  }
} T;
int size[N], f[N], fa[N][LOG], dep[N], Log2[N], dfn[N], inde;
inline void init() {
  for (int i = 1; i <= n; ++i) Log2[i] = Log2[i - 1] + (1 << Log2[i - 1] == i);
}
void dfs1(int u, int fat) {
  dep[u] = dep[fat] + 1;
  fa[u][0] = fat;
  size[u] = 1;
  dfn[u] = ++inde;
  for (int i = 1; i < Log2[dep[u]]; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = head[u], v; i; i = e[i].next) {
    v = e[i].to;
    dfs1(v, u);
    size[u] += size[v];
  }
}
inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[y]) x = fa[x][Log2[dep[x] - dep[y]] - 1];
  if (x == y) return x;
  for (int i = Log2[dep[x]] - 1; i >= 0; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
struct Query {
  int x, y, lca, w;
  inline void build() {
    x = read(), y = read();
    lca = LCA(x, y);
    w = read();
  }
} q[N];
vector<Query> vec[N];
void dfs2(int u) {
  int sum = 0;
  for (int i = head[u], v; i; i = e[i].next) {
    v = e[i].to;
    dfs2(v);
    sum += f[v];
  }
  f[u] = sum;
  for (int i = 0; i < vec[u].size(); ++i) {
    Query x = vec[u][i];
    f[u] = max(f[u], sum + T.query(dfn[x.x]) + T.query(dfn[x.y]) + x.w);
  }
  T.modify(dfn[u], dfn[u] + size[u] - 1, sum - f[u]);
}
int main() {
  n = read(), m = read();
  for (int i = 2, fat; i <= n; ++i) {
    fat = read();
    add(fat, i);
  }
  init();
  dfs1(1, 0);
  for (int i = 1; i <= m; ++i) {
    q[i].build();
    vec[q[i].lca].push_back(q[i]);
  }
  dfs2(1);
  printf("%d\n", f[1]);
  return 0;
}
