import std.stdio, std.conv, std.string, std.range, std.array, std.algorithm;
import std.bigint;

const char[] c = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];
const int[] a = [1, 5, 10, 50, 100, 500, 1000];

void main()
{
  while (true){
    string s = readln().chomp();
    if (s == "") break;
    int sum, l;
    for (int i = 0; i < s.length; i++){
      for (int j = 0; j < 7; j++){
        if (s[i] == c[j]){
          if (l >= a[j]){
            sum += a[j];
          } else {
            sum += a[j] - l * 2;
          }
          l = a[j];
        }
      }
    }
    writeln(sum);
  }
}