#include<stdio.h>

int main(){
char ch,;
int sum;
int w,b,a;
sum=0;ch='\0';w=0;b=0;a=0;
while(scanf("%c",&ch)!=EOF){
while(1){
if(ch=='\0')break;
if(ch=='I')w=1;
else if(ch=='V')w=5;
else if(ch=='X')w=10;
else if(ch=='L')w=50;
else if(ch=='C)w=100;
else if(ch=='D')w=500;
else if(ch=='M')w=1000;
switch(w){
case 1:
a=1;break;
case 5:
if(b==1)a=4;else a=5;break;
case 10:
if(b==1)a=9;else a=10;break;
case 50:
if(b==10)a=40;else a=50;break;
case 100:
if(b==10)a=90;else a=100;break;
case 500:
if(b==100)a=400;else a=500;break;
case 1000:
if(b==100)a=9;else a=1000;break;
}
sum+=a;b=a;
}
printf( "%d\n",sum);
sum=0;ch='\0';w=0;b=0;a=0;
}
return 0;
}