//Roman Figure
#include<bits/stdc++.h>
using namespace std;

int main(){
  string s;
  while(cin>>s){
    int ans=0;
    for(int i=0; i<s.length(); i++){
      int tmp;
      if(s[i]=='I')tmp=1;
      if(s[i]=='V')tmp=5;
      if(s[i]=='X')tmp=10;
      if(s[i]=='L')tmp=50;
      if(s[i]=='C')tmp=100;
      if(s[i]=='D')tmp=500;
      if(s[i]=='M')tmp=1000;

      if(tmp<=ans)ans+=tmp;
      else ans=tmp-ans;
    }
    cout<<ans<<endl;
  }
  return 0;
}