#include <iostream>
#include <cstdio>

using namespace std;

int main() {

	int n;
	char s[128];

	while(cin >> s) {
		n=0;
		for(int i=0; s[i]!='\0'; i++) {
			if(s[i]=='M') {
				n+=1000;
				if(s[i-1]=='D')
					n-=1000;
				else if(s[i-1]=='C')
					n-=200;
				else if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='D') {
				n+=500;
				if(s[i-1]=='C')
					n-=200;
				else if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='C') {
				n+=100;
				if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='L') {
				n+=50;
				if(s[i]=='X')
					n-=20;
				if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='X') {
				n+=10;
				if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='V') {
				n+=5;
				if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='I')
				n+=1;
		}
		cout << n << endl;

	}

	return 0;

}