class RomanFigure
  def initialize
    @table = {'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000}
    @judge = {'I' => ['V','X'], 'X' => ['L','C'], 'C' => ['D','M']} 
    @inputs = []
    input
    @inputs.each do |string|
     puts check(string)
    end
  end

  def input
    while input = $stdin.gets 
      @inputs << input.chomp
    end
  end

  def check(string)
    val = 0
    array = split_elements(string)
    array.each do |elem|
      val += calc_value(elem)
    end
    return val
  end

  def calc_value(string)
    case string.size
    when 1
      @table[string.slice(0,1)]
    when 2
      @table[string.slice(1,1)] - @table[string.slice(0,1)]
    end
  end

  def split_elements(string)
    count = 0
    before = ''
    result = []
    str = ''
    string.each_char do |ch|
      if @judge[str] != nil && @judge[str].include?(ch)
        str += ch
        result << str
        str = ''
      else
        result << str if str.size > 0
        str = ch
      end
    end
    result << str if str.size > 0
    return result
  end
end

r = RomanFigure.new