#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	string st;
	map<char, int>mp;
	mp['I'] = 0;
	mp['V'] = 1;
	mp['X'] = 2;
	mp['L'] = 3;
	mp['C'] = 4;
	mp['D'] = 5;
	mp['M'] = 6;
	
	vector<int>values{ 1,5,10,50,100,500,1000 };
	while (cin >> st) {
		vector<int>nums;
		for (auto c : st) {
			nums.push_back(mp[c]);
		}
		int sum = 0;
		for (int i = 0; i < nums.size(); ++i) {
			if (i == nums.size() - 1 || nums[i] >= nums[i + 1])sum += values[nums[i]];
			else sum -= values[nums[i]];
		}
		cout << sum << endl;

	}
	return 0;
}
#include <iostream>
#include <string>

using namespace std;

int roma[128];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    roma['I']=1;
    roma['V']=5;
    roma['X']=10;
    roma['L']=50;
    roma['C']=100;
    roma['D']=500;
    roma['M']=1000;
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string str;
    while(getline(cin, str)){
        int ans=roma[(unsigned)str[str.length()-1]];
        for(int i=str.length()-2; i>=0; i--){
            int rn=roma[(unsigned)str[i]];
            if(rn>=roma[(unsigned)str[i+1]]) ans+=rn;
            else ans-=rn;
        }
        cout<<ans<<'\n';
    }
    return 0;
}