#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;
		stack<int> stk;
		for(int i=0;i<str.size();i++){
			char* pos;
			if((pos = find(name,name+7,str[i])) != name+7){

				if(stk.empty()){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}

				else if(stk.top() < num[pos - name]){
					sum -= stk.top();
					sum += num[pos - name] - stk.top();
					stk.push(num[pos - name] - stk.top());
				}
				else if(stk.top() >= num[pos - name]){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}

	
}