import java.text.ParseException;
public class FromRoman {
public static final Integer[] divs = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
public static final String[] figs = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
public static void main(String[] args) throws ParseException {
String letter = args[0];
Integer number = 0;
int i = 0;
int j = 0;
while (i < letter.length()) {
if (i < letter.length() - 1) {
String twoletter = letter.substring(i, i + 2);
int twoindex = indexOf(j, twoletter);
if (twoindex != -1) {
number += divs[twoindex];
i = i + 2;
j = twoindex;
continue;
}
}
String oneletter = letter.substring(i, i + 1);
int oneindex = indexOf(j, oneletter);
if (oneindex != -1) {
number += divs[oneindex];
i++;
j = oneindex;
continue;
}
throw new ParseException(letter, i);
}
System.out.println(number);
}
public static int indexOf(int startIndex, String temp) {
for (int j = startIndex; j < figs.length; j++) {
if (temp.equals(figs[j])) {
return j;
}
}
return -1;
}
}