#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 101
#define MIN -100001
#define _MAX 8


int main(void)
{
	char roman[102];
	char fig[8] = { "IVXLCDM" };
	int value[7] = { 1,5,10,50,100,500,1000 };
	int  sum = 0, b = _MAX;
	while (scanf_s("%s", &roman, MAX) != EOF) {
		for (int i = 0; roman[i] != '\0'; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (roman[i] == fig[j]) {
					if (b >= j) sum += value[j];
					else { sum -= value[b]; sum += value[j] - value[b]; }
					b = j;
				}
			}
		}
		printf("%d\n", sum);
		sum = 0; b = _MAX;
	}
}
#include <iostream>
using namespace std;

int convert( char c )
{
    switch ( c )
    {
    case 'I':   return 1;
    case 'V':   return 5;
    case 'X':   return 10;
    case 'L':   return 50;
    case 'C':   return 100;
    case 'D':   return 500;
    case 'M':   return 1000;
    }
}

int main( void )
{
    string input;
    int answer, prev;
    while ( cin >> input )
    {
        answer = 0;
        prev = 0;

        for ( string ::reverse_iterator it = input.rbegin(); it != input.rend(); it++ )
        {
            int next = convert( *it );
            if ( prev <= next )
            {
                answer += next;
            }
            else
            {
                answer -= next;
            }
            prev = next;
        }

        cout << answer << endl;
    }
    return 0;
}