import std.stdio,
       std.string;

void main() {
    long[dchar] table = ['I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000];
    foreach(input; stdin.byLine) {
        dchar current = 'I';
        long sum = 0;
        foreach_reverse(dchar c; input) {
            if(table[c] < table[current]) {
                sum -= table[c];
            }
            else {
                sum += table[c];
                current = c;
            }
        }
        sum.writeln;
    }
}