import java.util.*;
import java.io.*;

public class Main implements Runnable {

	Scanner in;
	PrintWriter out;

	int toDate(String st) {
		int year = 0;
		if (st.endsWith("AD")) {
			year += 753;
			year += Integer.parseInt(st.substring(0, st.length() - 2));
		} else {
			year += 753 - Integer.parseInt(st.substring(0, st.length() - 2)) + 1;
		}
		return year;
	}

	String toRim(int year) {
		String line = "" + year;
		String ans = "";
		char cur = 0;
		if (line.length() == 4) {
			for (int i = 0; i < line.charAt(0)-'0'; i++) {
				ans += "M";
			}
			cur++;
		}
		if (line.length() >= 3) {
			int num = line.charAt(cur) - '0';
			if (num == 9) {
				ans += "CM";
			} else if (num == 8) {
				ans += "DCCC";
			} else if (num == 7) {
				ans += "DCC";
			} else if (num == 6) {
				ans += "DC";
			} else if (num == 5) {
				ans += "D";
			} else if (num == 4) {
				ans += "CD";
			} else if (num == 3) {
				ans += "CCC";
			} else if (num == 2) {
				ans += "CC";
			} else if (num == 1) {
				ans += "C";
			}
			cur++;
		}
		if (line.length() >= 2) {
			int num = line.charAt(cur) - '0';
			if (num == 9) {
				ans += "XC";
			} else if (num == 8) {
				ans += "LXXX";
			} else if (num == 7) {
				ans += "LXX";
			} else if (num == 6) {
				ans += "LX";
			} else if (num == 5) {
				ans += "L";
			} else if (num == 4) {
				ans += "XL";
			} else if (num == 3) {
				ans += "XXX";
			} else if (num == 2) {
				ans += "XX";
			} else if (num == 1) {
				ans += "X";
			}
			cur++;
		}
		if (line.length() >= 1) {
			int num = line.charAt(cur) - '0';
			if (num == 9) {
				ans += "IX";
			} else if (num == 8) {
				ans += "VIII";
			} else if (num == 7) {
				ans += "VII";
			} else if (num == 6) {
				ans += "VI";
			} else if (num == 5) {
				ans += "V";
			} else if (num == 4) {
				ans += "IV";
			} else if (num == 3) {
				ans += "III";
			} else if (num == 2) {
				ans += "II";
			} else if (num == 1) {
				ans += "I";
			}
			cur++;
		}
		return ans;
	}

	void solve() {
		String dates[] = in.nextLine().split("-");
		int start = toDate(dates[0]);
		int end = toDate(dates[1]);
		int maxSize = 1;
		for (int year = start; year <= end; year++) {
			String rim = toRim(year);
			maxSize = Math.max(maxSize, rim.length());
		}
		out.println(maxSize);
	}

	public void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

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