#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	string loma;
	while(cin >> loma){
		int arabia = 0;
		vector<int> lom(loma.size()+1);
		for (int i = 0; i < loma.size(); i++) {
			switch (loma.at(i)) {
			case 'I':lom.at(i) = 1; break;
			case 'V':lom.at(i) = 5; break;
			case 'X':lom.at(i) = 10; break;
			case 'L':lom.at(i) = 50; break;
			case 'C':lom.at(i) = 100; break;
			case 'D':lom.at(i) = 500; break;
			case 'M':lom.at(i) = 1000; break;
			}
		}
		for (int i = 0; i < loma.size(); i++) {
			if (lom.at(loma.size() - 1 - i) >= lom.at(loma.size() - i))
				arabia += lom.at(loma.size() - 1 - i);
			else
				arabia -= lom.at(loma.size() - 1 - i);
		}
		cout << arabia << endl;
	}
}
