#include <iostream>
#include <map>
#include <string>
#include <string.h>

using namespace std;

int main(){
    char str[101];
    int i,len,sum;
    map<char,int> table;
 
table['I'] = 1;
table['V'] = 5;
table['X'] = 10;
table['L'] = 50;
table['C'] = 100;
table['D'] = 500;
table['M'] = 1000;



while(cin>>str){
	len = strlen(str) - 1;
	
	sum = 0;
	for(i = 0; i < len; i++){
	    if(table[str[i]] < table[str[i+1]]){
	    	sum -= table[str[i]];
	    }
	    else{
	        sum += table[str[i]];
	    }
	}
	cout<<sum+table[str[len]]<<endl;
}
    
 return 0;   
}

