#include<iostream>
#include<string>
#include<map>

using namespace std;

int Search(char, map<int, char>);

int main(){
  int i, n, m, Arabic;
  string str;
  map<int, char> Roman;

  Roman[1] = 'I';
  Roman[5] = 'V';
  Roman[10] = 'X';
  Roman[50] = 'L';
  Roman[100] = 'C';
  Roman[500] = 'D';
  Roman[1000] = 'M';

  while(cin >> str){
    Arabic = 0;
    i = 0;
    while(i < str.size()-1){
      n = Search(str[i], Roman);
      m = Search(str[i+1], Roman);

      if(n < m){
	Arabic += (m-n);
	i += 2;
      }else{
	Arabic += n;
	++i;
	if(i == str.size()-1)
	  Arabic += m;
      }
    }

    cout << Arabic << endl;
  }

  return 0;
}

int Search(char c, map<int, char> x){
  map<int, char>::iterator iter = x.begin();
  while(iter != x.end()){
    if(c == iter->second)
      return iter->first;
    ++iter;
  }
  return 0;
}