#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;
}

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;
	}
}