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

void main()
{
    immutable int[dchar] L = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000];
    foreach(w;stdin.byLine())
    {
        int s=0,t=0,c=0;
        foreach(n;w.map!(a=>L[a])())
        {
            if(n==c) t+=c;
            if(n>c) s-=t,t=c=n;
            if(n<c) s+=t,t=c=n;
        }
        writeln(s+t);
    }
}