n,k,*rsp=(gets+gets).split.map &:to_i
t=gets.chomp.chars.map{|c| "spr".index(c) }
prev=[3]*k
p t.reduce(0){|s,e|
  pe=prev.shift
  if pe==e
    prev.push(3)
  else
    s+=rsp[e]
    prev.push(e)
  end
  s
}
