import java.io.*; //MUST IMPORT!!!

public class Q4
{
    //static Console c;           // The output console


    public static void main (String[] args) throws IOException //MUST!
    {
	//c = new Console ();


	BufferedReader input = new BufferedReader (new FileReader ("DATA4.txt"));
	PrintWriter output = new PrintWriter (new FileWriter ("OUT4.txt"));

	for (int line = 0 ; line < 5 ; line++)
	{
	    String nums = input.readLine ().toUpperCase ();
	    int[] numsa = new int [nums.length ()];
	    filla (nums, numsa);
	    int result = 0;


	    if (numsa.length == 1)
	    {
		result += numsa [0];
	    }
	    else
	    {
		for (int i = 0 ; (i < numsa.length - 1) ; i++)
		{
		    //System.out.println (numsa [i]);
		    if (numsa [i + 1] > numsa [i])
		    { // must be subtraction
			result += numsa [i + 1] - numsa [i];
			i++;
		    }
		    else
		    {
			result += numsa [i];
			if (i == numsa.length - 2)
			    result += numsa [i + 1];
		    }
		}
	    }
	    output.println (result);
	}
	output.close ();
	input.close ();
    } // main method


    public static void filla (String str, int[] arr)
    {
	char rome[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
	int romenum[] = {1, 5, 10, 50, 100, 500, 1000};
	for (int j = 0 ; j < str.length () ; j++)
	{
	    for (int k = 0 ; k < 7 ; k++)
		if (str.charAt (j) == rome [k])
		{
		    arr [j] = romenum [k];
		}
	}
    }
} // Text1 class

