#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string s;
	map<char, int> ex;
	ex['I'] = 1; ex['V'] = 5; ex['X'] = 10; ex['L'] = 50; 
	ex['C'] = 100; ex['D'] = 500; ex['M'] = 1000;
	
	while(cin >> s)
	{
		int sum = 0;
		for(int i = 0; i < s.size()-1; i++)
		{
			char now = s[i], next = s[i+1];

			if(ex[now] < ex[next])
			{
				sum -= ex[now];
			}
			else
			{
				sum += ex[now]; 
			}
		}
		sum += ex[s[s.size()-1]];
		cout << sum << endl;
	}
}
#include<iostream>
#include<string>
int main() {
	std::string s;
	while (std::cin >> s){
		int sum = 0;
		for (int i = 0; i != s.size(); i++){
			if (s[i] == 'I'){
				if (s[i + 1] == 'V') {
					sum += 4;i++;
				}
				else if (s[i + 1] == 'X'){
					sum += 9; i++;
				}
				else sum++;
			}
			else if (s[i] == 'V')sum += 5;
			else if (s[i] == 'X'){
				if (s[i + 1] == 'L'){
					sum += 40;i++;
				}
				else if (s[i + 1] == 'C'){
					sum += 90;i++;
				}
				else sum += 10;
			}
			else if (s[i] == 'L')sum += 50;
			else if (s[i] == 'C') {
				if (s[i + 1] == 'D'){
					sum += 400; i++;
				}
				else if (s[i + 1] == 'M'){
					sum += 900; i++;
				}
				else sum += 100;
			}
			else if (s[i] == 'D')sum += 500;
			else if (s[i] == 'M')sum += 1000;
		}
		std::cout << sum << std::endl;
	}
}