#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;


int main(void) {

  string alp = "IVXLCDM";
  int num[7] = {1, 5, 10, 50, 100, 500, 1000};

  string s;
  while(cin >> s){
    reverse(s.begin(), s.end());
    int n = 0;
    int b = 0;
    for(int i=0; i<s.size(); i++){
      for(int j=0; j<7; j++){
        if( s[i] == alp[j] ){
          // cerr << n << " " << b << endl;
          if( num[j] < b ) n -= num[j];
          else n += num[j];

          b = num[j];
        }
      }

    }
    cout << n << endl;

  }

  return 0;
}

// EOF
#include <stdio.h>

int main(void){
    char fig[101];
    int num;
    
    while (scanf("%s", fig) != EOF){
        num = 0;
        for (char *pt=fig; *pt!='\0'; pt++){
            switch (*pt){
            case 'I':
                switch(*(pt+1)){
                case 'V':
                    num += 4;
                    pt++;
                    break;
                case 'X':
                    num += 9;
                    pt++;
                    break;
                default:
                    num += 1;
                    break;
                }
                break;
            case 'V':
                num += 5;
                break; 
            case 'X':
                switch(*(pt+1)){
                case 'L':
                    num += 40;
                    pt++;
                    break;
                case 'C':
                    num += 90;
                    pt++;
                    break;
                default:
                    num += 10;
                    break;
                }
                break;
            case 'L':
                num += 50;
                break;
            case 'C':
                switch(*(pt+1)){
                case 'D':
                    num += 400;
                    pt++;
                    break;
                case 'M':
                    num += 900;
                    pt++;
                    break;
                default:
                    num += 100;
                    break;
                }
                break;
            case 'D':
                num += 500;
                break;
            case 'M':
                num += 1000;
                break;
            }
        }
        printf("%d\n", num);
    }
        
    return 0;
}