import std.stdio,std.string,std.conv;

int main()
{
	int[char] roman = ['I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000];
	string s;
	while((s = readln.chomp).length != 0)
	{
		int ans = 0;
		for(int i=0;i<s.length-1;i++)
		{
			if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]];
			else ans -= roman[s[i]];	
		}
		ans += roman[s[s.length-1]];
		writeln(ans);
	}
	return 0;
}