#include <iostream>
#include <string>
using namespace std;

int num(char ch) {
  if(ch=='I') return 1;
  if(ch=='V') return 5;
  if(ch=='X') return 10;
  if(ch=='L') return 50;
  if(ch=='C') return 100;
  if(ch=='D') return 500;
  if(ch=='M') return 1000;
}

int main() {
  string s;
  while(cin >> s) {
    int n=0,y=0;
    for(int i=s.size()-1; i>=0; i--) {
      int x=num(s[i]);
      if(x<y) n-=x;
      else {
	n+=x;
	y=x;
      }
    }
    cout << n << endl;
  }
  return 0;
}
