#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

char name[] = {'I','V','X','L','C','D','M'};
int num[] = {1,5,10,50,100,500,1000};

int main(){
	string str;
	while(1){
		cin >> str;
		int sum=0;
		for(int i=0;i<str.size();i++){
			char* pos;
			if((pos = find(name,name+7,str[i])) != name+7){
				int next;
				int now = num[pos-name];

				char* nextpos;
				if(i != str.size() - 1
					&& (nextpos = find(name,name+7,str[i+1])) != name+7){
					next = num[nextpos-name];
				}else{
					next = -1;
				}

				if(now >= next){
					sum += now;
				}else{
					sum += next - now;
					i++;
				}
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}
}