#include<iostream>
#include<vector>
#include<string>
using namespace std;

int get_arabic(char x){
  if(x=='I')return 1;
  else if(x=='V')return 5;
  else if(x=='X')return 10;
  else if(x=='L')return 50;
  else if(x=='C')return 100;
  else if(x=='D')return 500;
  else if(x=='M')return 1000;
}

int roma_to_arabic(string roma){
  int nums[100];
  for(int i=0;i<roma.length();i++){
    nums[i]=get_arabic(roma[i]);
  }
  for(int i=0;i<roma.length();i+=2){
    if(nums[i]>=nums[i+1])nums[i]=nums[i]+nums[i+1];
    else if(nums[i]<nums[i+1])nums[i]=nums[i+1]-nums[i];
  }

  int retu=0;
  for(int i=0;i<roma.length();i+=2){
    retu+=nums[i];
  }
  return retu;
}
int main(){
  vector<int> answers;
  string roma_num;
  while(cin>>roma_num){
    answers.push_back(roma_to_arabic(roma_num));
  }
  for(int i=0;i<answers.size();i++){
    cout<<ansers[i]<<endl;
  }
}