#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	string s;
	while(cin >> s){
		char b[s.size()];
		for(int i=0;i<s.size();i++) b[i] = s[i];
		int k[3] = {1,1,1};
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and (b[i+1]=='X' or b[i+1]=='V')) k[0] = -1;
			if(b[i]=='X' and (b[i+1]=='L' or b[i+1]=='C')) k[1] = -1;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) k[2] = -1;
		}
		bool cs = false;
		bool ce = false;
		bool xs = false;
		bool xe = false;
		int w = 0;
		for(int i=0;i<s.length();i++){
			int a;
			if(b[i]=='M') a = 1000;
			if(b[i]=='D') a = 500;
			if(b[i]=='C'){
				if(ce) a = 100*k[2];
				else   a = 100;
				if(not cs) cs = true;
			}
			else if(cs) ce = true;
			if(b[i]=='L') a = 50;
			if(b[i]=='X'){
				if(xe) a = 10*k[1];
				else   a = 10;
				if(not xs) xs = true;
			}
			else if(xs) xe = true;
			if(b[i]=='V') a = 5;
			if(b[i]=='I') a = k[0];
			w += a;
		}
		cout << w << endl;
	}
}