#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 w = 0;
		for(int i=0;i<s.length();i++){
			if(b[i]=='M') w += 1000;
			if(b[i]=='D') w += 500;
			if(b[i]=='C') w += 100;
			if(b[i]=='L') w += 50;
			if(b[i]=='X') w += 10;
			if(b[i]=='V') w += 5;
			if(b[i]=='I') w += 1;
		}
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and b[i+1]!='I') w -= 2;
			if(b[i]=='V' and (b[i+1]!='V' and b[i+1]!='I')) w -= 10;
			if(b[i]=='X' and (b[i+1]!='X' and b[i+1]!='V' and b[i+1]!='I')) w -= 20;
			if(b[i]=='L' and (b[i+1]=='C' or b[i+1]=='D' or b[i+1]=='M')) w -= 100;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) w -= 200;
			if(b[i]=='D' and b[i+1]=='D') w -= 500;
		}
		cout << w << endl;
	}
}