import std.stdio;
import std.string;

enum {
    I = 1,
    V = 5,
    X = 10,
    L = 50,
    C = 100,
    D = 500,
    M = 1000
}


void main()
{
    while (true) {
        auto input = readln().chomp;
        if (input.length == 0) break;
        int total = 0;

        for (int i = 0; i < input.length; i++) {
            if (convRtoA(input[i]) < convRtoA(input[i+1])) {
                total += convRtoA(input[i+1]) - convRtoA(input[i]);
                i++;
            } else {
                total += convRtoA(input[i]);
            }
        }

        writeln(total);
    }
}


int convRtoA(char c)
{
    switch (c) {
    case 'I': return 1; break;
    case 'V': return 5; break;
    case 'X': return 10; break;
    case 'L': return 50; break;
    case 'C': return 100; break;
    case 'D': return 500; break;
    case 'M': return 1000; break;
    default: return 0;
    }
}