#include <map>
#include <string>
#include <iostream>
using namespace std;
int main(){
	int i,r;
	string s;
	map<char,int>m;
	for(m['I']=1,m['V']=5,m['X']=10,m['L']=50,m['C']=100,m['D']=500,m['M']=1000;getline(cin,s);cout<<r<<endl)for(i=r=0;i<s.size();i++)r+=m[s[i]]*(m[s[i]]<m[s[i+1]]?-1:1);
}
#include<iostream>
#include<string>
using namespace std;

int Roman_to_Arabia(char c){
	if (c == 'I')return 1;
	else if (c == 'V')return 5;
	else if (c == 'X')return 10;
	else if (c == 'L')return 50;
	else if (c == 'C')return 100;
	else if (c == 'D')return 500;
	else if (c == 'M')return 1000;
	else return 0;
}

int main(){
	string roman;
	int num;

	while (cin >> roman){
		num = 0;

		for (int i = 0; i < roman.size(); ++i){

			if (Roman_to_Arabia(roman[i]) < Roman_to_Arabia(roman[i + 1]))
				num -= Roman_to_Arabia(roman[i]);
			else
				num += Roman_to_Arabia(roman[i]);			
		}
		cout << num << endl;
	}
	return 0;
}