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


int main(){
  int sum,i,j,kari;
  string data;
  while(getline(cin, data)) {
    data = data.insert(data.length(), "KKKKKK");
    sum = j = 0;
    
    for(j = 0; j < data.length(); j++) {
      if(data[j] == 'M'){
	sum += 1000;
      }else if(data[j] == 'D'){
	if(data[j + 1] == 'M'){
	  sum += 900;
	    j++;
	}else{
	  sum += 500;
	}
      }else if(data[j] == 'C'){
	if(data[j + 1] == 'D' || data[j + 1] == 'M'){
	  if(data[j + 1] == 'D'){
	    sum += 400;
	    j++;
	  }else{
	    sum += 900;
	    j++;
	  }
	}else{
	  sum += 100;
	}
      }else if(data[j] == 'L'){
	sum += 50;
      }else if(data[j] == 'X'){
	if(data[j+1] == 'L' || data[j+1] == 'C'){
	  if(data[j+1] == 'L'){
	    sum += 40;
	    j++;
	  }else{
	    sum += 90;
	    j++;
	  }
	}else{
	  sum += 10;
	}
      }else if(data[j] == 'V'){
	sum += 5;
      }else if(data[j] == 'I'){
	if(data[j + 1] == 'V' || data[j + 1] == 'X'){
	  if(data[j + 1] == 'V'){
	    sum += 4;
	    j++;
	  }else{
	    sum += 9;
	    j++;
	  }
	}
	else{
	  sum += 1;
	}
      }
    }
    
    cout << sum << endl;
  }
  
  return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int roman_to_n(const string& s)
{
	static const int num[] = { 1, 5, 10, 50, 100, 500, 1000 };
	static const char* roman = "IVXLCDM";

	vector<int> digits(s.size());
	for (int i = 0; i < s.size(); ++i)
		digits[i] = num[strchr(roman, s[i]) - roman];

	int res = accumulate(digits.begin(), digits.end(), 0);
	for (int i = 0; i < digits.size() - 1; ++i)
		if (digits[i] < digits[i + 1])
			res -= 2 * digits[i];
	return res;
}
string to_roman(int n)
{
	static const char* roman[][10] = {
		{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }, 
		{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
		{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
		{ "", "M", "MM", "MMM", "MMMM", "MMMMM" },
	};

	stringstream res;
	for (int i = 3, j = 1000; i >= 0; --i, j /= 10)
		res << roman[i][(n / j) % 10];
	return res.str();
}
int main()
{
	string s;
	while (cin >> s)
		cout << roman_to_n(s) << endl;
}