f 'I'=1;f 'V'=5;f 'X'=10;f 'L'=50;f 'C'=100;f 'D'=500;f _=1000;l@main=getLine>>=print.snd.foldr(\a(b,s)->(a,s+signum(a-b+1)*a))(0,0).map f>>l