#include<stdio.h>
#include<string.h>

int main(){
	int num=0,i,j=0,math[1000]={0};
	char mozi[1000]={0};
	
	while(scanf("%s",mozi)!=EOF){
		num=0;
		for(i=0;i<strlen(mozi);i++){
			if(mozi[i]=='I')math[i]=1;
			else if(mozi[i]=='V')math[i]=5;
			else if(mozi[i]=='X')math[i]=10;
			else if(mozi[i]=='L')math[i]=50;
			else if(mozi[i]=='C')math[i]=100;
			else if(mozi[i]=='D')math[i]=500;
			else if(mozi[i]=='M')math[i]=1000;
		}
		for(i=(strlen(mozi)-1);i>=0;i--){
			if(math[i]<math[i-1] && i!=0){num+=(math[i-1]+math[i]); i--;}
			else if(math[i]>math[i-1] && i!=0){num+=(math[i]-math[i-1]); i--;}
			else if(math[i]==math[i-1] || i==0)num+=math[i];
		}
		printf("%d\n",num);
	}
	
return 0;
}