#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string t;
    map<char, int> v;
    v['I'] = 1; v['V'] = 5; v['X'] = 10; v['L'] = 50; v['C'] = 100; v['D'] = 500; v['M'] = 1000;
    while(getline(cin, t)){
        int mx = 0, ans = 0;
        for (int i = t.size()-1; i >= 0; --i) {
            if(mx <= v[t[i]]){
                mx = v[t[i]];
                ans += v[t[i]];
            }else {
                ans -= v[t[i]];
            }
        }
        cout << ans << "\n";
    }
    return 0;
}
