#include <stddef.h>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  size_t i, r;
  string s;
  map<char, int> m;
  m['I'] = 1;
  m['V'] = 5;
  m['X'] = 10;
  m['L'] = 50;
  m['C'] = 100;
  m['D'] = 500;
  m['M'] = 1000;
  while (cin >> s) {
    for (i = r = 0; i < s.size(); i++)
      r += m[s[i]] * (m[s[i]] < m[s[i + 1]] ? -1 : 1);
    cout << r << endl;
  }
}