#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
using namespace std;

int main(){
	string s;
	while(cin >> s){
		int i = 0,num[100] = {},j = 0;
		while(s[i] != '\0'){
			if(s[i] == 'I'){
				i++;
				num[j] += 1;
				while(s[i] == 'I'){
					i++;
					num[j] += 1;
				}
				j++;
			}else if(s[i] == 'V'){
				i++;
				num[j] += 5;
				while(s[i] == 'V'){
					i++;
					num[j] += 5;
				}
				j++;
			}else if(s[i] == 'X'){
				i++;
				num[j] += 10;
				while(s[i] == 'X'){
					i++;
					num[j] += 10;
				}
				j++;
			}else if(s[i] == 'L'){
				i++;
				num[j] += 50;
				while(s[i] == 'L'){
					i++;
					num[j] += 50;
				}
				j++;
			}else if(s[i] == 'C'){
				i++;
				num[j] += 100;
				while(s[i] == 'C'){
					i++;
					num[j] += 100;
				}
				j++;
			}else if(s[i] == 'D'){
				i++;
				num[j] += 500;
				while(s[i] == 'D'){
					i++;
					num[j] += 500;
				}
				j++;
			}else if(s[i] == 'M'){
				i++;
				num[j] += 1000;
				while(s[i] == 'M'){
					i++;
					num[j] += 1000;
				}
				j++;
			}
		}
		i = 0;
		int pre = 1e9,res = 0;
		while(num[i] != 0){
			if(pre < num[i]){
				res -= pre * 2;
			}
			res += num[i];
			pre = num[i];
			i++;
		}
		cout << res << endl;
	}
}
