#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

vector<string> v;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);
    map<char, int> mp;
    mp['M'] = 1000;
    mp['D'] = 500;
    mp['C'] = 100;
    mp['L'] = 50;
    mp['X'] = 10;
    mp['V'] = 5;
    mp['I'] = 1;
    string s;
    while (cin >> s)
    {
        int n = s.size();
        int sum = mp[s[n - 1]];
        for (int i = n - 1; i >= 1; --i)
        {
            if (mp[s[i]] > mp[s[i - 1]])
            {
                sum -= mp[s[i - 1]];
            }
            else
            {
                sum += mp[s[i - 1]];
            }
        }
        cout << sum << endl;
    }
    return 0;
}
