import std.stdio;
import std.string;

enum conv = [
             'I':1,
             'V':5,
             'X':10,
             'L':50,
             'C':100,
             'D':500,
             'M':1000
             ];


void main()
{
    foreach (input; stdin.byLine()){
        int total = 0;
        if (input.length == 1)
            total = conv[input[0]];
        else {
            foreach (i; 1..input.length) {
                if (conv[input[i - 1]] < conv[input[i]]) {
                    total -= conv[input[i - 1]];
                } else {
                    total += conv[input[i - 1]];
                }
            }
            total += conv[input[$ - 1]];
        }
        total.writeln;
    }
}