def query(x)
  return x if $mark[x]
  query($arr[x])
end
loop do
  n, q = gets.split.map(&:to_i)
  break if n == 0
  $arr = Array.new(n+1)
  (2..n).each{ |i| $arr[i] = gets.to_i }
  $mark = Array.new(n+1)
  $mark[1] = true
  sum = 0
  q.times do
    cmd, n = gets.split
    if cmd == 'Q'
      ans = query(n.to_i)
      sum += ans
    else
      $mark[n.to_i] = true
    end
  end
  p sum
end