#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <climits>
#include <vector>
#include <algorithm>
#include <utility>
#include <array>
#include <limits>
 
template <typename F>
class fix_point: F {
public:
  explicit constexpr fix_point(F&& f) noexcept: F(std::forward<F>(f)) {}
 
  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return F::operator ()(*this, std::forward<Args>(args)...);
  }
};
 
template <typename F>
static inline constexpr decltype(auto) make_fix_point(F&& f) noexcept {
  return fix_point<F>{std::forward<F>(f)};
}
 
template <typename Weight>
struct edge {
  using value_type = Weight;
  size_t src, dst;
  value_type cost;
 
  edge(size_t src, size_t dst, value_type cost = 1):
    src(src), dst(dst), cost(cost)
  {}
 
  bool operator <(edge<value_type> const& rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};
 
template <typename Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  using value_type = Weight;
  graph(size_t n): std::vector<std::vector<edge<value_type>>>(n) {}
 
  void connect_with(size_t src, size_t dst, value_type cost = 1) {
    (*this)[src].emplace_back(src, dst, cost);
    (*this)[dst].emplace_back(dst, src, cost);
  }
};
 
template <typename Tp>
std::array<std::vector<size_t>, 2> euler_tour(graph<Tp> const& g, size_t s = 0) {
  std::array<std::vector<size_t>, 2> res;
  res[0] = res[1] = std::vector<size_t>(g.size());
  size_t j = 0;
  make_fix_point([&](auto dfs, size_t i, size_t pi) -> void {
    res[0][i] = j++;
    for (auto const& e: g[i]) {
      if (e.dst == pi) continue;
      dfs(e.dst, i);
    }
    res[1][i] = j++;
  })(s, -1);
  return res;
}
 
template <typename Tp>
std::vector<size_t> depth(graph<Tp> const& g, size_t s = 0) {
  std::vector<size_t> res(g.size());
  make_fix_point([&](auto dfs, size_t i, size_t pi) -> void {
    for (auto const& e: g[i]) {
      if (e.dst == pi) continue;
      res[e.dst] = res[e.src] + 1;
      dfs(e.dst, e.src);
    }
  })(s, -1);
  return res;
}
 
template <
  typename Monoid,
  typename Container = std::vector<typename Monoid::first_type>,
  typename SubContainer = std::vector<typename Monoid::second_type>
>
class segment_tree {
public:
  using first_type = typename Monoid::first_type;
  using second_type = typename Monoid::second_type;
  using value_type = first_type;
  using binary_operation = typename Monoid::binary_operation;
  using external_binary_operation = typename Monoid::external_binary_operation;
  using merge_operation = typename Monoid::merge_operation;
  using container = Container;
  using sub_container = SubContainer;
 
private:
  size_t M_base_size;
  binary_operation M_op1;
  external_binary_operation M_op2;
  merge_operation M_op3;
  container M_c;
  sub_container M_d;  // deferred
 
  void M_build(size_t i) {
    while (i > 1) {
      i >>= 1;
      M_c[i] = M_op2(M_op1(M_c[i<<1|0], M_c[i<<1|1]), M_d[i]);
    }
  }
 
  void M_resolve(size_t i) {
    size_t h = (sizeof(size_t) * CHAR_BIT) - __builtin_clzll(M_base_size*2);
    for (size_t s = h; s > 0; --s) {
      size_t p = i >> s;
      if (M_d[p] != M_op3.identity) {
        M_apply(p<<1|0, M_d[p]);
        M_apply(p<<1|1, M_d[p]);
        M_d[p] = M_op3.identity;
      }
    }
  }
 
  void M_apply(size_t i, second_type const& x) {
    M_c[i] = M_op2(M_c[i], x);
    if (i < M_base_size) M_d[i] = M_op3(M_d[i], x);
  }
 
public:
  segment_tree() = default;
  segment_tree(segment_tree const&) = default;
  segment_tree(segment_tree&&) = default;
 
  segment_tree(size_t n, first_type const& x = binary_operation().identity):
    M_base_size(n),
    M_op1(binary_operation()),
    M_op2(external_binary_operation()),
    M_op3(merge_operation()),
    M_c(n+n, x), M_d(n, M_op3.identity)
  {
    for (size_t i = n; i--;)
      M_c[i] = M_op1(M_c[i<<1|0], M_c[i<<1|1]);
  }
 
  template <typename InputIt>
  segment_tree(InputIt first, InputIt last):
    M_base_size(std::distance(first, last)),
    M_op1(binary_operation()),
    M_op2(external_binary_operation()),
    M_op3(merge_operation()),
    M_c(M_base_size*2), M_d(M_base_size, M_op3.identity)
  {
    for (size_t i = M_base_size; first != last; ++i)
      M_c[i] = *first++;
    for (size_t i = M_base_size; i--;)
      M_c[i] = M_op1(M_c[i<<1|0], M_c[i<<1|1]);
  }
 
  segment_tree& operator =(segment_tree const&) = default;
  segment_tree& operator =(segment_tree&&) = default;
 
  void modify(size_t l, size_t r, second_type const& x) {
    l += M_base_size;
    r += M_base_size;
    size_t l0 = l;
    size_t r0 = r;
    while (l < r) {
      if (l & 1) M_apply(l++, x);
      if (r & 1) M_apply(--r, x);
      l >>= 1;
      r >>= 1;
    }
    M_build(l0);
    M_build(r0-1);
  }
 
  first_type accumulate(size_t l, size_t r) {
    first_type resl = M_op1.identity;
    first_type resr = resl;
    l += M_base_size;
    r += M_base_size;
    M_resolve(l);
    M_resolve(r-1);
    while (l < r) {
      if (l & 1) resl = M_op1(resl, M_c[l++]);
      if (r & 1) resr = M_op1(M_c[--r], resr);
      l >>= 1;
      r >>= 1;
    }
    return M_op1(resl, resr);
  }
 
  first_type operator [](size_t i) {
    i += M_base_size;
    M_resolve(i);
    return M_c[i];
  }
};
 
namespace std {
  template <typename T1, typename T2>
  struct numeric_limits<std::pair<T1, T2>> {
    static std::pair<T1, T2> constexpr min() {
      return std::make_pair(std::numeric_limits<T1>::min(), std::numeric_limits<T2>::min());
    }
  };
}
 
template <typename Tp>
struct range_max_range_max {
  using first_type = Tp;
  using second_type = Tp;
  struct binary_operation {
    first_type identity = std::numeric_limits<Tp>::min();
    first_type operator ()(first_type const& x, first_type const& y) const {
      return std::max(x, y);
    }
  };
  struct external_binary_operation {
    first_type operator ()(first_type const& x, second_type const& y) const {
      return std::max(x, y);
    }
  };
  struct merge_operation {
    second_type identity = std::numeric_limits<Tp>::min();
    second_type operator ()(second_type const& x, second_type const& y) const {
      return std::max(x, y);
    }
  };
};
 
int testcase_ends() {
  size_t n, q;
  scanf("%zu %zu", &n, &q);
  if (n == 0 && q == 0) return 1;
 
  graph<int> g(n);
  for (size_t i = 1; i < n; ++i) {
    size_t p;
    scanf("%zu", &p);
    --p;
    g.connect_with(i, p);
  }
 
  auto d = depth(g);
  auto et = euler_tour(g);

  // {depth, nma}
  segment_tree<range_max_range_max<std::pair<size_t, size_t>>> st(n+n, std::make_pair(0, 0));
 
  size_t res = 0;
  for (size_t i = 0; i < q; ++i) {
    char t;
    size_t v;
    scanf(" %c %zu", &t, &v);
    --v;
 
    if (t == 'Q') {
      res += st[et[0][v]].second+1;
    } else if (t == 'M') {
      st.modify(et[0][v], et[1][v]+1, std::make_pair(d[v], v));
    }
  }
 
  printf("%zu\n", res);
  return 0;
}
 
int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 29636