#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>

using namespace std;

static map<char, int> Dictionary;

int ParseRomanNumber(const char *roman) {
  int len = strlen(roman);
  if (len == 0) { return 0; }

  int acc = 0;
  int curr, next = Dictionary[roman[0]];
  for (int i = 1; i < len; ++i) {
    curr = next;
    next = Dictionary[roman[i]];
    acc += curr < next ? -curr : curr;
  }
  acc += Dictionary[roman[len - 1]];
  return acc;
}

int main() {
  Dictionary['I'] = 1;
  Dictionary['V'] = 5;
  Dictionary['X'] = 10;
  Dictionary['L'] = 50;
  Dictionary['C'] = 100;
  Dictionary['D'] = 500;
  Dictionary['M'] = 1000;

  char *line = nullptr;
  size_t buffer_size = 0;
  ssize_t len;
  while ((len = getline(&line, &buffer_size, stdin)) > 0) {
    for (ssize_t i = len - 1; i >= 0 and isspace(line[i]); --i) {
      line[i] = '\0';
    }
    printf("%d\n", ParseRomanNumber(line));
  }
  free(line);

  return 0;
}