#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
//I V X L C D M
int main (int argc, char const* argv[]) {
  string raw;
  string map = "IVXLCDM";
  const int weight[7] = {1,5,10,50,100,500,1000};
  while (cin >> raw) {
    int list[7], sum = 0;
    memset(list, 0, sizeof list);
    int loc = map.find(raw[0]);
    sum += weight[loc];
    //cout<<sum<<endl;
    for (int i = 1; i < raw.size(); i += 1) {
      int nloc = map.find(raw[i]);
      if (loc < nloc) {
        sum = sum - weight[nloc];
      } else {
        sum += weight[nloc];
      }
      //cout<<sum<<endl;
      loc = nloc;
    }
    cout << abs(sum) << endl;
  }
  return 0;
}