import java.io.*;
public class NumerosRomanos
{
public static void main (String[] args)
{
String sRomano;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.print("Ingresa numero romano:");
sRomano = stdin.readLine();
int iValor = 0;
int iIndex = 0;
while( iIndex < sRomano.length() )
{
if( sRomano.substring(iIndex, iIndex + 1).equals("I") )
{
if( sRomano.length() >= iIndex + 2)
{
if( sRomano.substring(iIndex + 1, iIndex + 2).equals("V") )
{
iValor += 4;
iIndex += 2;
}
else if( sRomano.substring(iIndex + 1, iIndex + 2).equals("X"))
{
iValor += 9;
iIndex += 2;
}
else if( sRomano.substring(iIndex + 1, iIndex + 2).equals("I"))
{
if( sRomano.length() >= iIndex + 3)
{
if( sRomano.substring(iIndex + 2, iIndex + 3).equals("I"))
{
iValor += 3;
iIndex += 3;
}
}
else
{
iValor += 2;
iIndex += 2;
}
}
}
else
{
iValor += 1;
iIndex += 1;
}
}
else if( sRomano.substring(iIndex, iIndex + 1).equals("V") )
{
iValor +=5;
iIndex +=1;
}
else if( sRomano.substring(iIndex, iIndex + 1).equals("X") )
{
if( sRomano.length() >= iIndex + 2)
{
if( sRomano.substring(iIndex + 1, iIndex + 2).equals("L") )
{
iValor += 40;
iIndex += 2;
}
else if( sRomano.substring(iIndex + 1, iIndex + 2).equals("C"))
{
iValor += 90;
iIndex += 2;
}
else if( sRomano.substring(iIndex + 1, iIndex + 2).equals("X"))
{
if( sRomano.length() >= iIndex + 3)
{
if( sRomano.substring(iIndex + 2, iIndex + 3).equals("X"))
{
iValor += 30;
iIndex += 3;
}
}
else
{
iValor += 20;
iIndex += 2;
}
}
}
else
{
iValor += 10;
iIndex += 1;
}
}
}
System.out.println(" Valor : " + iValor);
stdin.close();
}
catch (Exception e)
{
System.out.println("Error");
}
}
}