#include <stdio.h>
#include <string.h>
int main()
{
char in[101];
int d[101], ca[101]={0}, i,j,a,b,x,y,top=0, I=1, V=5, X=10, L=50, C=100, D=500, M=1000;
int cp=0, anw[101];
scanf("%s", in); //ca = 크기 , d = 계산
for(i=0; i<strlen(in); i++) // 크기 저장
{
if(in[i]=='I') ca[cp++] = 1;
else if(in[i]=='V') ca[cp++] = 5;
else if(in[i]=='X') ca[cp++] = 10;
else if(in[i]=='L') ca[cp++] = 50;
else if(in[i]=='C') ca[cp++] = 100;
else if(in[i]=='D') ca[cp++] = 500;
else if(in[i]=='M') ca[cp++] = 1000;
}
cp=0;
for(i=0;i<strlen(in);i+=2) //AR 계산 (완료)
{
d[i] = (in[i]-'0') * ca[cp++];
printf("d[%d] = in[%d](%d) * in[%d](%d) : %d\n", i, i, in[i]-'0', i, ca[i], d[i]);
}
for(i=0;i<strlen(in);i++) //크기비교, 연산자 선택
{
if(0<i)
{
if(ca[i] >= ca[i+1])
{
d[i] = d[i-1] + d[i];
printf("ANW[%d] = d[%d](%d) + d[%d](%d):%d\n", i,i,d[i],i-1,d[i-1],d[i-1]);
}
else
{
d[i] = d[i] - d[i-1];
}
}
}
printf("%d", anw[strlen(anw)]);
}



