#include <iostream>
#include <string>
#include <map>
#include <cstdint>

int main()
{
	typedef std::map<char, std::uint32_t> RomanToInt;
	RomanToInt roman_map;
	roman_map.insert(std::make_pair('I', 1U));
	roman_map.insert(std::make_pair('V', 5U));
	roman_map.insert(std::make_pair('X', 10U));
	roman_map.insert(std::make_pair('L', 50U));
	roman_map.insert(std::make_pair('C', 100U));
	roman_map.insert(std::make_pair('D', 500U));
	roman_map.insert(std::make_pair('M', 1000U));

	std::string input;
	while (std::getline(std::cin, input)) {
		std::uint32_t value = 0;
		bool prev_minus = false;
		for (std::uint32_t i = 0; i < input.size(); ++i) {
			std::uint32_t num = roman_map[input[i]];
			if ((not prev_minus) and (i + 1 < input.size())) {
				if (num < roman_map[input[i + 1]]) {
					num = -num;
					prev_minus = true;
				}
			}
			else {
				prev_minus = false;
			}
			value += num;
		}
		std::cout << value << std::endl;
	}

	return 0;
}