import java.util.*;
public class cpromJ {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
//as I, V, X, L, C, D and M has a single value such as 1, 5, 10, 50, 100, 500 and 1000
int i = 1,v = 5, X = 10, l = 50, c = 100, d = 500, m = 1000;
while(scn.hasNextLine()) {
String s = scn.nextLine();
StringTokenizer st = new StringTokenizer(s, " ");
boolean subtract = true;
while(st.hasMoreTokens()) {
String sub = st.nextToken();
int arr [] = new int[sub.length()];
for(int x=0;x<sub.length();x++) {
if(sub.charAt(x)== \'I\') {
arr[x] = i;
}
else if(sub.charAt(x)== \'V\') {
arr[x] = v;
}
else if(sub.charAt(x)== \'X\') {
arr[x] = X;
}
else if(sub.charAt(x)== \'L\') {
arr[x] = l;
}
else if(sub.charAt(x)== \'C\') {
arr[x] = c;
}
else if(sub.charAt(x)== \'D\') {
arr[x] = d;
}
else if(sub.charAt(x)== \'M\') {
arr[x] = m;
}
}
int total=0;
if(subtract) {
for(int x=0;x<arr.length;x++) {
if(arr[x] < arr[x+1]) {
if(subtract) {
subtract = false;
total = arr[x+1]-arr[x];
x++;
}
else {
total += arr[x];
}
}
else {
total += arr[x];
}
}
}
else {
for(int x=0;x<arr.length;x++) {
total += arr[x];
}
}
System.out.println(total);
}
}
}
}