import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Solver implements Runnable {
	BufferedReader br;
	StringTokenizer sr;
	PrintWriter pr;

	public static void main(String[] args) {
		new Solver().run();
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			pr = new PrintWriter(System.out);
			
//			pr.println(get(nextInt()));
			
			int a, b;
			String[] s = br.readLine().split("-");
			a = Integer.parseInt(s[0].substring(0, s[0].length() - 2));
			b = Integer.parseInt(s[1].substring(0, s[1].length() - 2));
			
			if (s[0].charAt(s[0].length() - 1) == 'C') {
				a = 754 - a;
			} else {
				a += 753;
			}
			
			if (s[1].charAt(s[1].length() - 1) == 'C') {
				b = 754 - b;
			} else {
				b += 753;
			}
			
			//HashSet<Integer> h  = new HashSet<I>();
			int ans = 0;
			
			for (int i = a; i <= b; i++) {
				String str = get(i);
				ans = Math.max(ans, str.length());
			}
			
			pr.println(ans);
			pr.flush();
			
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}		
	}
	
	String get(int n) {
		String s = "";
		
		int r = n / 1000;
		
		while (r > 0) {
			s = s + "M";
			--r;
		}
		
		n %= 1000;		
		r = n / 100;
		
		if (r > 0) {
			if (r == 4) {
				s += "CD";
				r = 0;
			} 
			
			if (r == 9) {
				s += "CM";
				r = 0;
			} 
			
			if (r >= 5) {
				s += "D";
				r -= 5;
			}
			
			for (int i = 0; i < r; i++) {
				s += "C";					
			}			
		}
		
		n %= 100;
		r = n / 10;
		
		if (r > 0) {
			if (r == 4) {
				s += "XL";
				r = 0;
			} 
			
			if (r == 9) {
				s += "XC";
				r = 0;
			} 
			
			if (r >= 5) {
				s += "L";
				r -= 5;
			}
			
			for (int i = 0; i < r; i++) {
				s += "X";					
			}			
		}
		
		n %= 10;
		r = n;
		
		if (r > 0) {
			if (r == 4) {
				s += "IV";
				r = 0;
			} 
			
			if (r == 9) {
				s += "IX";
				r = 0;
			} 
			
			if (r >= 5) {
				s += "V";
				r -= 5;
			}
			
			for (int i = 0; i < r; i++) {
				s += "I";					
			}			
		}
		
		return s;
	}
	
	String nextToken() throws IOException {
		while (sr == null || !sr.hasMoreTokens()) {
			sr = new StringTokenizer(br.readLine());
		}
		
		return sr.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}
	
	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}
