#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	map<char, int> dic;
	dic['I'] = 1;
	dic['V'] = 5;
	dic['X'] = 10;
	dic['L'] = 50;
	dic['C'] = 100;
	dic['D'] = 500;
	dic['M'] = 1000;
	while (true) {
		string S = ""; cin >> S;
		if (S == "") break;
		int N = S.size();
		int ans = 0;
		rep(i,N) {
			if (i != N-1) {
				if (dic[S[i]] < dic[S[i+1]]) ans -= dic[S[i]];
				else ans += dic[S[i]];
			} else ans += dic[S[i]];
		}
		cout << ans << endl;
	}

}

