Dict_input=dict(I=1, V=5, X=10, L=50, C=100, D=500, M=1000)
Dict_Output =[ {'0':'', '1':'I', '2':'II', '3':'III', '4':'IV', '5':'V', '6':'VI', '7':'VII', '8':'VIII', '9':'IX'},
{'0':'', '1':'X', '2':'XX', '3':'XXX', '4':'XL', '5':'L', '6':'LX', '7':'LXX', '8':'LXXX', '9':'XC'},
{'0':'', '1':'C', '2':'CC', '3':'CCC', '4':'CD', '5':'D', '6':'DC', '7':'DCC', '8':'DCCC', '9':'CM'},
{'0':'', '1':'M', '2':'MM', '3':'MMM'},]
while True:
output=''
try:
a,b = input().split()
except Exception as e:
break
else:
if a==b:
output = "ZERO"
else:
a = list(a)
b = list(b)
c=[]
d=[]
for x in a:
c.append(Dict_input.get(x)) #把A的每個字拆開
for x in b:
d.append(Dict_input.get(x)) #把B的每個字拆開
Len = len(c) #把A加總
if Len>1:
sum_1 = 0
tmp = c[0]
for i in range(1,Len):
if (c[i]>c[i-1]):
sum_1 += c[i] -tmp
tmp = 0
elif (c[i]==c[i-1]):
tmp += c[i]
else:
sum_1 += tmp
tmp = c[i]
if c[i]<=c[i-1]:
sum_1 += tmp
else:
sum_1 = c[0]
Len = len(d) #把B加總
if Len>1:
sum_2 = 0
tmp = d[0]
for i in range(1,Len):
if (d[i]>d[i-1]):
sum_2 += d[i] - tmp
tmp = 0
elif (d[i]==d[i-1] and i< (Len-1)):
tmp += d[i]
else:
sum_2 += tmp
tmp = d[i]
if (d[i]<=d[i-1]):
sum_2 += tmp
else:
sum_2 = d[0]
#print(sum_1)
#print(sum_2)
sum_1 = abs (sum_1 - sum_2)
#print(sum_1)
sum_1 = list(str(sum_1))
#print(sum_1)
Len = len(sum_1);
for i in range(Len): #查字典把每個位的羅馬數字拼起來再輸出
output += Dict_Output[Len-1-i].get(sum_1[i])
print(output)