#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)

int main()
{
  string str;
  //  string roman[] = {"I", "V", "X", "L", "C", "D", "M"};
  map<char, int> roman;
  roman['I'] = 1;
  roman['V'] = 5;
  roman['X'] = 10;
  roman['L'] = 50;
  roman['C'] = 100;
  roman['D'] = 500;
  roman['M'] = 1000;

  while(cin>>str){
    int nums[str.size()];
    REP(i,str.size())
      nums[i] = roman[str[i]];

    int dec=0;    
    int begin=0;
    int i=0;
    while(i<str.size()-1){
      if(nums[i] < nums[i+1]){
	for(int j=begin; j<=i; j++){
	  dec += nums[j];
	  nums[j] = 0;
	}
	begin = i+2;
      }
      if(nums[i] > nums[i+1]){
	begin = i+1;
      }
      i++;
    }

    int res=0;
    REP(i,str.size()) res += nums[i];

    cout << res-dec << endl;
  }

  return 0;
}
#include <iostream>
using namespace std;

int main()
{
	char rome[110];
  int	num, ara, nu;
	while(cin >> rome){
		num = ara = nu = 0;
		for(int i = 0; rome[i] != '\0'; i++){
			if (rome[i] == 'I') num = 1;
			else if (rome[i] == 'V') num = 5;
			else if (rome[i] == 'X') num = 10;
			else if (rome[i] == 'L') num = 50;
			else if (rome[i] == 'C') num = 100;
			else if (rome[i] == 'D') num = 500;
			else if (rome[i] == 'M') num = 1000;

			if (nu < num)	ara += num - nu - nu;
			else ara += num;
			nu = num;
		}
		cout << ara << endl;
	}
	return (0);
}