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

int main() {
	string in;
	int n = 0;
	while (cin >> in) {
		n = 0;
		in += '\0';
		for (int i = 0; i < in.size(); i++) {
			if (in[i] == 'M')
				n += 1000;
			if (in[i] == 'D')
				n += 500;
			if (in[i] == 'L')
				n += 50;
			if (in[i] == 'V')
				n += 5;
			if (in[i] == 'C') {
				if (in[i+1] == 'M' || in[i+1] == 'D')
					n -= 100;
				else
					n += 100;
			}
			if (in[i] == 'X') {
				if (in[i+1] == 'C' || in[i+1] == 'L')
					n -= 10;
				else
					n += 10;
			}
			if (in[i] == 'I') {
				if (in[i+1] == 'X' || in[i+1] == 'V')
					n -= 1;
				else
					n += 1;
			}
		}
		cout << n << endl;
	}
}
