#include <stdio.h>
#include <string.h>

char zad[10000];
int nexts[7][10000];

int idx[256];
char zn[8] = "ivxlcdm";

void find_nexts (int n, int *nxts, char zn)
{
  int i;

  nxts[n] = n;
  for (i = n - 1; i >= 0; i--)
    if (zad[i] == zn)
      nxts[i] = i;
    else
      nxts[i] = nxts[i + 1];
}

int move_to_next (char zn, int *pos, int n)
{
  int apos = *pos + 1;

  apos = nexts[idx[(int) zn]][apos];
  if (apos == n)
    return 0;

  *pos = apos;
  return 1;
}

int anys (char *s, int pos, int n)
{
  for (; *s; s++)
    if (!move_to_next (*s, &pos, n))
      return 0;

  return 1;
}

int main(void)
{
	idx['i']= 0, idx['v'] = 1, idx['x'] = 2, idx['l'] = 3, idx['c'] = 4, idx['d'] = 5, idx['m'] = 6;
  int n, i, j, val;

  while (1)
    {
      if (!gets (zad)
	  || !*zad)
	return 0;
      n = strlen (zad);

      for (i = 0; i < 7; i++)
	find_nexts (n, nexts[i], zn[i]);

      i = -1;
      val = 0;

      /* First, get all m's.  */
      while (move_to_next ('m', &i, n))
	val += 1000;

      /* Get d if available.  */
      if (move_to_next ('d', &i, n))
	val += 500;

      /* now, cccxc > ccc > cc > c */
      for (j = 0; j < 3; j++)
	if (!move_to_next ('c', &i, n))
	  break;
      val += 100 * j;

      if (anys ("xc", i, n))
	{
	  move_to_next ('x', &i, n);
	  move_to_next ('c', &i, n);
	  val += 90;
	}
      else
	{
	  /* Get l if available.  */
	  if (move_to_next ('l', &i, n))
	    val += 50;

	  /* xxx > xxx > xx > x */
	  for (j = 0; j < 3; j++)
	    if (!move_to_next ('x', &i, n))
	      break;
	  val += 10 * j;
	}


      if (anys ("ix", i, n))
	val += 9;
      else
	{
	  /* Get v if available.  */
	  if (move_to_next ('v', &i, n))
	    val += 5;

	  /* And as much i's as possible.  */
	  for (j = 0; j < 3; j++)
	    if (!move_to_next ('i', &i, n))
	      break;
	  val += j;
	}
      printf ("%d\n", val);
    }
}
