#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	string s;
	vector<pair<string, int>> r = {make_pair("M", 1000), make_pair("D", 500), make_pair("C", 100), make_pair("L", 50), make_pair("X", 10), make_pair("V", 5), make_pair("I", 1)};
	for (; cin >> s;)
	{
		int sum = 0;
		int add = 0;
		int old = 0;
		for (int i = 0; i < s.length(); i++)
		{
			for (int j = 0; j < r.size(); j++)
			{
				if (s.substr(i, 1) == r.at(j).first)
				{
					int n0 = r.at(j).second;
					if (old > 0 && old < n0)
					{
						sum -= 2 * old;
						old = 0;
					}
					sum += n0;
					old = n0;
					break;
				}
			}
		}

		// sum += add + old;

		cout << sum << endl;
	}
}

