import re
import sys

def is_proper_roman_numeral(s):
     return re.fullmatch('(?xi)'
         '(?=[MDCLXVI])'
         '(?P<thousands> M{,3})'
         '(?P<hundreds>D?C{,3}|CM|CD)'
         '(?P<tens>    L?X{,3}|XC|XL)'
         '(?P<units>   V?I{,3}|IX|IV)', s)

for line in sys.stdin:
    line = line.strip()
    NOT = " NOT" * (not is_proper_roman_numeral(line))
    print("{line!r} is{NOT} valid".format(**vars()))