import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	s = chomp(s);
	int ans = 0;
	for(int i=0;i<s.length;i++){
	    char c = s[i];
	    int n1,n2;
	    if(c == 'I') n1 = 1;
	    else if (c=='V') n1 = 5;
	    else if (c=='X') n1 = 10;
	    else if (c=='L') n1 = 50;
	    else if (c=='C') n1 = 100;
	    else if (c=='D') n1 = 500;
	    else if (c=='M') n1 = 1000;
	    if(i<to!int(s.length)-1){
		c = s[i+1];
		if(c == 'I') n2 = 1;
		else if (c=='V') n2 = 5;
		else if (c=='X') n2 = 10;
		else if (c=='L') n2 = 50;
		else if (c=='C') n2 = 100;
		else if (c=='D') n2 = 500;
		else if (c=='M') n2 = 1000;
		if(n1 < n2){
		    n1 = n2 - n1;
		    i++;
		}
	    }
	    ans += n1;
	}
	writeln(ans);
    }

}