#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


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

bool same(vector<int> n){
	rep(i,n.size()-1){
		if(n[i]!=n[i+1])return false;
	}
	return true;
}
//CCCCLXXXXVIIII
int main(){
	string str;
	while( cin>>str ){
		vector<int> s;
		int sum = 0;

		s.clear();
		rep(i,str.size()) s.pb( toNum(str[i]) );

		while( s.size() ){
			vector<int> tmp;
			int back = s.size()-1;
			for( int i=back;i>=back-3;i-- ){
				tmp.pb(s[i]);
				if( i==0 || ( i!=back && s[i]!=s[i+1] ) )break;
			}
			reverse(all(tmp));

			if( same(tmp) ){
				sum+=tmp[tmp.size()-1];
				s.erase(s.begin()+back);
			}
			else if( tmp[0] <tmp[1]  ){
				sum += tmp[1]-tmp[0];
				s.erase(s.begin()+back);
				s.erase(s.begin()+back-1);
			}
			else{
				sum += tmp[0]+tmp[1]*(tmp.size()-1);
				rep(i,tmp.size()){
					s.erase(s.begin()+(back-i));
				}
			}
		}
		cout<<sum<<endl;
	}
}




/*
		while(1){
			int pos = -1;
			int last = s.size()-1;
			for(i,3){
				if( last-i-1<1 ||  s[last-i]!=s[last-i-1] ){
					pos = last-i-1;
					break;
				}
			}
			if( pos==-1 ){
				sum+=s[last];
				s.erase(s.begin()+last);
			}
			else{
				if( s[pos]<s[pos+1] ){
					sum += s[pos]-s[pos-1];
					s.erase( s.begin()+pos );
					s.erase( s.begin()+(pos-1) );
				}
			}
		}

}



int main(){
	string str;
	while( cin>>str ){
		vector<int> s;
		int sum = 0;

		s.clear();
		rep(i,str.size()) s.pb( toNum(str[i]) );

		while( s.size()>0 ){
			int maxi = -1;
			int pos = -1;
			rep(i,s.size()){
				if( s[i]>=maxi ){
					maxi = s[i];
					pos = i;
				}
			}
			if( pos!=0 && s[pos-1]<s[pos] ){
				sum += s[pos]-s[pos-1];
				s.erase( s.begin()+pos );
				s.erase( s.begin()+(pos-1) );
			}
			else if( s[pos-1]>=s[pos] && pos != s.size()-1 ){
				int times = 1;
				for(int i=2;i<=3;i++){
					if( pos+i >= s.size())break;
					if( s[pos]+i == s[pos]+i-1 )times++;
				}
				sum += s[pos] + s[pos+1]*times;
				rep(i,times+1){
					s.erase( s.begin()+pos );
				}

			}else{
				sum += s[pos];
				s.erase( s.begin()+pos );
			}
		}
		cout<<sum<<endl;
	}
}
*/