#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int check(char str);
int counter(int res,char *str);
int main(){
    char str[128]={0};
    while(~scanf("%s",str)){

        /*宣言*/
        int ans = 0,bef = 0;
        int cnt = 1;
        int len = strlen(str);
        int x;
        bool f = false;
        /*宣言終了*/

        reverse(str,str+len);
        rep(i,len){
            x = check(str[i]);
            if(!f){
                bef = x;
                f = true;
                continue;
                cnt++;
            }
            if(bef == x){
                cnt++;
            }
            else if(bef < x){
                ans += cnt*bef;
                cnt = 1;
                bef = x;
            }
            else{
                int coun = counter(i,str);
                ans += (bef*cnt) - (coun*x);
                cnt = 1;
                f = false;
                i += coun-1;
            }
        }
        if(x == bef)ans += cnt*bef;
        printf("%d\n",ans);
    }
	return 0;
}
int check(char str){
    if(str == 'I')return 1;
    if(str == 'V')return 5;
    if(str == 'X')return 10;
    if(str == 'L')return 50;
    if(str == 'C')return 100;
    if(str == 'D')return 500;
    if(str == 'M')return 1000;
}
int counter(int res , char *str){
    int cnt = 1;
    for(int i = res; str[i] != str[res] ; i++){
        cnt++;
    }
    return cnt;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int main()
{
	char* ara = "IVXLCDM";
	int num[] = { 1, 5, 10, 50, 100, 500, 1000 };

	char buf[101];
	while (scanf("%s\n", buf) != EOF)
	{
		int len = strlen(buf);
		int n[100];
		for (int i = 0; i < len; ++i)
		{
			for (int j = 0; j < 7; ++j)
			{
				if (buf[i] == ara[j])
				{
					n[i] = num[j];
					break;
				}
			}
		}
		for (int i = 0; i < len-1; ++i)
			n[i] *= n[i] < n[i+1] ? -1 : 1;

		int res = 0;
		for (int i = 0; i < len; ++i)
			res += n[i];

		printf("%d\n", res);
	}

	return 0;
}