// Arup Guha
// 12/25/2015
// Solution to UCF 1987 HS Contest Problem: Roman Numerals

import java.util.*;

public class roman {

	// What we need to store for any roman numeral.
	public String numeral;
	public int value;

	// Stores the letters representing digits 1, 5 and 10 in digit location i.
	final public static String[] LETTERS = {"IVX","XLC", "CDM", "MQZ"};
	public static HashMap<Character,Integer> map;

	public static void main(String[] args) {

		// Look up table for ease.
		map = new HashMap<Character,Integer>();
		map.put('M', 1000);
		map.put('D', 500);
		map.put('C', 100);
		map.put('L', 50);
		map.put('X', 10);
		map.put('V', 5);
		map.put('I', 1);

		Scanner stdin = new Scanner(System.in);
		while (stdin.hasNext()) {

			// Read in numbers as roman numerals.
			roman op1 = new roman(stdin.next());
			roman op2 = new roman(stdin.next());

			// Add them.
			roman res = op1.add(op2);

			// Print it!
			System.out.println(res);
		}
	}

	public roman(String letters) {
		numeral = letters;
		value = getValue();
	}

	public roman(int myval) {
		value = myval;
		numeral = getNumeral();
	}

	public String toString() {
		return numeral;
	}

	// Returns the sum of this and other in a new roman object.
	public roman add(roman other) {
		return new roman(this.value+other.value);
	}

	public int getValue() {

		int res = 0, last = 10000;

		// Go through each letter.
		for (int i=0; i<numeral.length(); i++) {

			// Typical case - we add.
			int next = map.get(numeral.charAt(i));
			res += next;

			// In this case, we should have subtracted the previous value,
			// so we must subtract twice to compensate.
			if (next > last) res -= (2*last);

			// Update last.
			last = next;
		}

		// Here is our result.
		return res;
	}

	public String getNumeral() {

		String res = "";
		int saveval = value, i = 0;

		// Build each set of numerals per digit location (from right to left).
		while (saveval > 0) {

			// Split off next digit and prepend numerals.
			int cur = saveval%10;
			res = formLetter(cur, i)+ res;

			// Get to next digit.
			i++;
			saveval /= 10;
		}

		return res;
	}

	// Forms the letters that correspond to the digit digit in the location power.
	public String formLetter(int digit, int power) {
		if (digit == 0) return "";
		if (digit < 4) return "" + mult(LETTERS[power].charAt(0), digit);
		if (digit == 4) return "" + LETTERS[power].charAt(0) + LETTERS[power].charAt(1);
		if (digit < 9) return "" + LETTERS[power].charAt(1) + mult(LETTERS[power].charAt(0), digit-5);
		return "" + LETTERS[power].charAt(0) + LETTERS[power].charAt(2);
	}

	// This function makes me wish I had python for this problem! (Returns c repated num times.)
	public static String mult(char c, int num) {
		String res = "";
		for (int i=0; i<num; i++)
			res = res + c;
		return res;
	}
}
