#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	string str;

	while(cin>>str){
    int ans=0;
        for(int i=0;;i++){

            if(str[i]=='M')ans+=1000;
            else if(str[i]=='D')ans+=500;
            else if(str[i]=='C'&&str[i+1]=='D')ans+=400,i++;
            else if(str[i]=='C')ans+=100;
            else if(str[i]=='L')ans+=50;
            else if(str[i]=='X'&&str[i+1]=='L')ans+=40,i++;
            else if(str[i]=='X')ans+=10;
            else if(str[i]=='V')ans+=5;
            else if(str[i]=='I'&&str[i+1]=='V')ans+=4,i++;
            else if(str[i]=='I')ans+=1;
            else if(str[i]==0)break;

        }

        cout<<ans<<endl;
        ans=0;

        str="";
	}


	return 0;
}