import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex;
import std.container;

void main()
{
	int[char] pat;
	pat['I'] = 1;
	pat['V'] = 5;
	pat['X'] = 10;
	pat['L'] = 50;
	pat['C'] = 100;
	pat['D'] = 500;
	pat['M'] = 1000;
	foreach (line; stdin.byLine) {
		int pre;
		int sum;
		foreach_reverse(c; line.chomp) {
			auto v = pat[c];
			if (pre <= v) {
				sum += v;
			} else {
				sum -= v;
			}
			pre = v;
		}
		sum.writeln;
	}
}