#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	int a,m,i;
	int n[256];
	n['I']=1;
	n['V']=5;
	n['X']=10;
	n['L']=50;
	n['C']=100;
	n['D']=500;
	n['M']=1000;

	char s[128];
	while(cin >> s)
	{
		for(a=m=0,i=strlen(s)-1; i>=0; i--)
		{
			if(n[s[i]]<m)	{ a-=n[s[i]]; }
			else			{ a+=m=n[s[i]]; }
		}
		cout << a << endl;
	}
}