#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void){

	string mo("IVXLCDM");
	int zi[]={1,5,10,50,100,500,1000};
	int ans;
	string inp;

	while(cin>>inp){
		ans=0;
		if(inp.length()>=2){
			for(int i=0;i<inp.length();i+=2){
				if(zi[mo.find(inp[i])]>=zi[mo.find(inp[i+1])]) ans+=zi[mo.find(inp[i])]+zi[mo.find(inp[i+1])];
				else ans+=zi[mo.find(inp[i+1])]-zi[mo.find(inp[i])];
			}
			if(inp.length()%2==1) ans+=zi[mo.find(inp[inp.length()-1])];
			cout<<ans<<endl;
		}
		else cout<<zi[mo.find(inp[0])]<<endl;
	}


	return 0;
}