#include <bits/stdc++.h>
using namespace std;

bool match( char ch, const string& p ) {
	for( auto a: p ) {
		if( a == ch ) { return true; }
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	while( cin >> s ) {
		int n = (int)s.size();
		int result = 0;

		for( int i = n-1; i >= 0; --i ) {
			if( s[i] == 'I' ) {
				result += i < n-1 && s[i+1] != 'I' ? -1 : 1;
			}
			else if( s[i] == 'V' ) {
				result += i < n-1 && match( s[i+1], "XLCDM" ) ? -5 : 5;
			}
			else if( s[i] == 'X' ) {
				result += i < n-1 && match( s[i+1], "LCDM" ) ? -10 : 10;
			}
			else if( s[i] == 'L' ) {
				result += i < n-1 && match( s[i+1], "CDM" ) ? -50 : 50;
			}
			else if( s[i] == 'C' ) {
				result += i < n-1 && match( s[i+1], "DM" ) ? -100 : 100;
			}
			else if( s[i] == 'D' ) {
				result += i < n-1 && match( s[i+1], "M" ) ? -500 : 500;
			}
			else if( s[i] == 'M' ) {
				result += 1000;
			}
		}

		cout << result << endl;
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char c[101],m[7]={'I','V','X','L','C','D','M'};
	int s,i,j,h,n[7]={1,5,10,50,100,500,1000};
  while(gets(c)!=NULL) {
    s=0; h=10;
	for (i=0;i<strlen(c);i++) {
     for (j=0;j<7;j++) if (c[i]==m[j]) break;
	 s+=n[j];
	 if (h<j) s-=n[h]*2;
	 h=j;
	}
    cout << s << endl;
  }
  return 0;
}