import java.util.*;

public class Main {
    // Map Roman numeral characters to values
    private static final Map<Character, Integer> romanMap = new HashMap<>();
    static {
        romanMap.put('I', 1);
        romanMap.put('V', 5);
        romanMap.put('X', 10);
        romanMap.put('L', 50);
        romanMap.put('C', 100);
        romanMap.put('D', 500);
        romanMap.put('M', 1000);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String roman = sc.nextLine().trim();

        // Input validation: only uppercase Roman characters allowed
        if (!roman.matches("[IVXLCDM]+")) {
            System.out.println("Invalid input");
            return;
        }

        int result = romanToInt(roman);

        // If the result is negative (though Romans usually aren’t negative)
        if (result < 0) {
            System.out.println("-1");
        } else {
            System.out.println(result);
        }
    }

    // Method to convert Roman numeral string to integer
    public static int romanToInt(String s) {
        int total = 0;
        int prevValue = 0;

        for (int i = s.length() - 1; i >= 0; i--) {
            int value = romanMap.get(s.charAt(i));

            if (value < prevValue) {
                total -= value;  // Subtract in cases like IV, IX
            } else {
                total += value;  // Normal addition
            }

            prevValue = value;
        }
        return total;
    }
}
