%h=@0=M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1=~/\d+|\D+/g;$"='|';<>;$s+=$h{$_}for<>=~/@0/g;print+($_)=grep$h{$_}&&$s>=$h{$_},@0while$s<4e3?$s-=$h{$_}:!print"ERROR"