roman={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}



try:

    while True:

        x=[]

        line = input()

        tmp = roman[line[0]]

        x.append(tmp)

        for c in line[1:]:

            tmp = roman[c]

            if x[-1]<tmp: x[-1] = -x[-1]

            x.append(tmp)

        print(sum(x))

except:

    pass
import sys

roman={"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}



for s in sys.stdin:

    x=[]

    tmp = roman[s[0]]

    x.append(tmp)

    for c in s[1:-1]:

        tmp = roman[c]

        if x[-1]<tmp: x[-1] *= -1

        x.append(tmp)

    print(sum(x))
roman = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
try:
    while True:
        x = []
        line = input()
        tmp = roman[line[0]]
        x.append(tmp)
        for c in line[1:]:
            tmp = roman[c]
            if x[-1] < tmp:
                x[-1] = -x[-1]
            x.append(tmp)
        print(sum(x))
except:
    pass

import sys

roman = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
for s in sys.stdin:
    x = []
    tmp = roman[s[0]]
    x.append(tmp)
    for c in s[1:-1]:
        tmp = roman[c]
        if x[-1] < tmp:
            x[-1] *= -1
        x.append(tmp)
    print(sum(x))

+import sys + -try: -    while True: -        x = [] -        line = input() -        tmp = roman[line[0]] +for s in sys.stdin: +    x = [] +    tmp = roman[s[0]] +    x.append(tmp) +    for c in s[1:-1]: +        tmp = roman[c] +        if x[-1] < tmp: +            x[-1] *= -1 -        for c in line[1:]: -            tmp = roman[c] -            if x[-1] < tmp: -                x[-1] = -x[-1] -            x.append(tmp) -        print(sum(x)) -except: -    pass +    print(sum(x))