import std.stdio;

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

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