import java.io.*;
import java.util.*;

public class ProgramIV {

	public static int getValueOfChar(String input) {
		if (input.equals("M")) {
			return 1000;
		}else if (input.equals("D")) {
			return 500;
		}else if (input.equals("C")) {
			return 100;
		}else if (input.equals("L")) {
			return 50;
		}else if (input.equals("X")) {
			return 10;
		}else if (input.equals("V")) {
			return 5;
		}else if (input.equals("I")) {
			return 1;
		}else{
			return -9999;
		}
	}

	public static void main(String args[]) throws Exception {
		BufferedReader in = new BufferedReader(new FileReader("DATA4.txt"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("OUT4.txt")));
		for (int i=0; i<5; i++) {
			String line = in.readLine();
			int sum = 0;
			int tempSum = 0;
			String lastChar = "";
			for (int c=0; c<line.length(); c++) {
				String curChar = line.substring(c,c+1);
				if (lastChar.equals(curChar)) {
					tempSum += getValueOfChar(curChar);
				}else{
					if (getValueOfChar(lastChar) > getValueOfChar(curChar)) {
						sum += tempSum;
						tempSum = getValueOfChar(curChar);
					}else{
						tempSum = getValueOfChar(curChar) - tempSum;
					}
				}
				lastChar = curChar;
			}
			if (tempSum > 0) {
				sum += tempSum;
				tempSum = 0;
			}
			out.println(sum);
		}
		out.close();
		System.exit(0);
	}
}
