using System;

namespace AOJ0039
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) break;

                int count = 0;

                for (int i = 0; i < input.Length; i++)
                {
                    switch (Convert.ToChar(input[i]))
                    {
                        case 'I':
                            if (i == input.Length - 1)
                            {
                                count += 1;
                            } else
                            {
                                if (input[i+1] == 'V')
                                {
                                    count += 4;
                                    i++;
                                } else if (input[i+1] == 'X')
                                {
                                    count += 9;
                                    i++;
                                } else
                                {
                                    count += 1;
                                }
                            }
                            break;
                        case 'V':
                            count += 5;
                            break;
                        case 'X':
                            if (i == input.Length - 1)
                            {
                                count += 10;
                            }
                            else
                            {
                                if (input[i + 1] == 'L')
                                {
                                    count += 40;
                                    i++;
                                }
                                else if (input[i + 1] == 'C')
                                {
                                    count += 90;
                                    i++;
                                }
                                else
                                {
                                    count += 10;
                                }
                            }
                            break;
                        case 'L':
                            count += 50;
                            break;
                        case 'C':
                            if (i == input.Length - 1)
                            {
                                count += 100;
                            }
                            else
                            {
                                if (input[i + 1] == 'D')
                                {
                                    count += 400;
                                    i++;
                                }
                                else if (input[i + 1] == 'M')
                                {
                                    count += 900;
                                    i++;
                                }
                                else
                                {
                                    count += 100;
                                }
                            }
                            break;
                        case 'D':
                            count += 500;
                            break;
                        case 'M':
                            count += 1000;
                            break;

                    }
                }

                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 9048