function main() {
  var
  romanTable = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000,
  };
  function roman(str) {
    var
    i, c,
    res = 0,
    len = str.length,
    back = Infinity;
    for(i = 0; i < len; i++) {
      c = str.charAt(i);
      res += romanTable[c];
      if(romanTable[c] > back) {
        res -= back*2;
      }
      back = romanTable[c];
    }
    return res;
  }
  
  input.forEach(function(line) {
    if(line.trim() === '') return;
    console.log(roman(line.trim()));
  });
  
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});