#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;

int main(void){
	map <char, int> m;
	vi x;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	while (true){
		string roman;
		cin>>roman;
		if (cin.eof()) break;

		int tmp, tmp2= m[roman[0]];
		for (int i=0; i<(int)roman.size(); i++){
			tmp = m[roman[i]];
			if (i!=0 && tmp2<tmp)
				x[i-1] = -tmp2;
			x.push_back(tmp);
			tmp2 = tmp;
		}

		int s=0;
		for (int i=0; i<(int)x.size(); i++)
			s += x[i];
		cout<<s<<endl;
		x.clear();
	}
}
#include<iostream>
#include<string>
using namespace std;
int main(){
long i,l,m,n,y;
string s;
while(cin>>s){
l=s.size();
y=0;m=1001;
for(i=0;i<l;i++){
if(s[i]=='I')n=1;
else if(s[i]=='V')n=5;
else if(s[i]=='X')n=10;
else if(s[i]=='L')n=50;
else if(s[i]=='C')n=100;
else if(s[i]=='D')n=500;
else if(s[i]=='M')n=1000;
if(m<n)y-=m*2;
y+=n;
m=n;
}
cout<<y<<endl;
}
return 0;
}