MaxN = 100000

# $Tree[1] がroot
def initTree
  $Tree = Array.new(MaxN+1)
  0.upto(MaxN+1) do |i|
    $Tree[i] = i
  end
end

# if $Marked[x] == x, then it is marked.
def initMarked
  $Marked = Array.new(MaxN+1, 0)
  $Marked[1] = 1
end

def mark(x)
  $Marked[x] = x
end

def isMarked(x)
  $Marked[x] == x
end

def nearestMarked(x)
  reservedX = x

  # x is marked.
  if isMarked(x)
    x
  # find the nearest marked ancestor, then connect the nodes above x to
  # the nearest marked ancestor.
  else
    $Marked[x] = nearestMarked($Tree[x])
  end
end

if __FILE__ == $0
  loop do
    n, q = gets.split.map(&:to_i)
    break if n.zero? && q.zero?

    initTree
    initMarked
    count = 0

    (n-1).times do |i|
      m = gets.to_i
      $Tree[i+2] = m
    end

    q.times do |i|
      op, m = gets.chomp.split
      m = m.to_i
      op == "M" ? mark(m) : count += nearestMarked(m)
    end
    # p $Tree[0,n]
    #  p $Marked[0,n]
    p count
  end
end