#include <iostream>
#include <vector>
#include <string>

using namespace std;

void solve()
{
	string str;
	while(cin >> str)
	{
		vector<int> Vec;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == 'M')
			{
				Vec.push_back(1000);
			}
			else if(str[i] == 'D')
			{
				Vec.push_back(500);
			}
			else if(str[i] == 'C')
			{
				Vec.push_back(100);
			}
			else if(str[i] == 'L')
			{
				Vec.push_back(50);
			}
			else if(str[i] == 'X')
			{
				Vec.push_back(10);
			}
			else if(str[i] == 'V')
			{
				Vec.push_back(5);
			}
			else if(str[i] == 'I')
			{
				Vec.push_back(1);
			}
		}
		int sum = 0;
		bool flag = false;
		for(int i = 0; i < Vec.size() - 1; ++i)
		{
			flag = false;
			if(Vec[i] < Vec[i + 1])
			{
				sum += Vec[i + 1] - Vec[i];
				++i;
				flag = true;
			}
			else
			{
				sum += Vec[i];
			}
		}
		if(!flag)
		{
			sum += Vec[Vec.size() - 1];
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}