#include <vector>
#include <iostream>
#include <map>
using namespace std;
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	map<char,int> t;
	t['I']=1, t['X']=10, t['V'] = 5;
	t['L'] = 50 , t['C'] = 100 , t['M'] = 1000 , t['D'] = 500;
	string s;
	while(cin >> s){
		int ret = 0;
		ret += t[s[0]];
		rep(i,s.length()-1){
			if(t[s[i+1]] > t[s[i]])ret -= 2*t[s[i]];
			ret += t[s[i+1]];
		}
		cout << ret << endl;
	}
}
#include <iostream>
#include <string>
using namespace std;

int main() {
  string str;
  while(getline(cin, str)) {
    int before = 0;
    int now;
    int ans = 0;
    for(int i = 0; i < str.length(); i++) {
      switch(str[i]) {
      case 'I': now = 1; break;
      case 'V': now = 5; break;
      case 'X': now = 10; break;
      case 'L': now = 50; break;
      case 'C': now = 100; break;
      case 'D': now = 500; break;
      case 'M': now = 1000; break;
      }
      if(now > before) {
	ans = ans - before + (now - before);
      } else {
	ans += now;
      }

      before = now;
    }


    cout << ans << endl;
  }
  return 0;
}