import java.util.*;

public class RomanToInteger {
    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 input = sc.nextLine().trim();

        // 1. Check for negative Roman
        if (input.contains("-")) {
            System.out.println("-1");
            return;
        }

        // 2. Validate input → only uppercase Roman characters allowed
        if (!input.matches("[IVXLCDM]+")) {
            System.out.println("Invalid input");
            return;
        }

        // 3. Convert to integer
        int result = romanToInt(input);
        System.out.println(result);
    }

    // Conversion logic
    private 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;
            } else {
                total += value;
            }
            prevValue = value;
        }

        return total;
    }
}