import scala.io.StdIn.readLine

object Main {
  def getNum(c:Char) = c match {
    case 'I' => 1
    case 'V' => 5
    case 'X' => 10
    case 'L' => 50
    case 'C' => 100
    case 'D' => 500
    case 'M' => 1000
    case _ => 0
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_!=null).foreach { s =>
      var prev = getNum(s(0))
      var sum = prev
      for(j<-1 until s.length) {
        val n = getNum(s(j))
        if(n>prev) sum += n -(2*prev) else sum += n
        prev = n
      }
      println(sum)
    }
  }
}