#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;

#define int64 long long
#define uint64 unsigned long long
#define pb push_back
#define mp make_pair
#define M_PI 3.1415926535898


struct point {
	int x, y;
	point(int x, int y) {
		this->x = x;
		this->y = y;
	}
};

double volume(double angle, int d, int l) {
	double D = d + 2 * l * sin(angle);
	double r = d / 2;
	double R = D / 2;
	double h = r / tan(angle);
	double H = l * cos(angle) + h;
	double s = M_PI * r * r;
	double S = M_PI * R * R;
	double v = s * h / 3;
	double V = S * H / 3;
	return V - v;
}

int toAUC(string s) {
	if (s.substr(s.length() - 2) == "BC") {
		int y;
		sscanf(s.substr(0, s.length() - 2).c_str(), "%d", &y);
		return 754 - y;
	}
	else {
		int y;
		sscanf(s.substr(0, s.length() - 2).c_str(), "%d", &y);
		return 753 + y;
	}
}

string toRoman(int year) {
	string ans = "";
	while (year >= 1000) {
		ans += "M";
		year -= 1000;
	}
	while (year >= 900) {
		ans += "CM";
		year -= 900;
	}
	while (year >= 500) {
		ans += "D";
		year -= 500;
	}
	while (year >= 400) {
		ans += "CD";
		year -= 400;
	}
	while (year >= 100) {
		ans += "C";
		year -= 100;
	}
	while (year >= 90) {
		ans += "XC";
		year -= 90;
	}
	while (year >= 50) {
		ans += "L";
		year -= 50;
	}
	while (year >= 40) {
		ans += "XL";
		year -= 40;
	}
	while (year >= 10) {
		ans += "X";
		year -= 10;
	}
	while (year >= 9) {
		ans += "IX";
		year -= 9;
	}
	while (year >= 5) {
		ans += "V";
		year -= 5;
	}
	while (year >= 4) {
		ans += "IV";
		year -= 4;
	}
	while (year > 0) {
		ans += "I";
		--year;
	}
	return ans;
}

int main() {
	string s;
	getline(cin, s);
	size_t minus = s.find('-');
	string first = s.substr(0, minus);
	string second = s.substr(minus + 1);
	int fst = toAUC(first), snd = toAUC(second);
	int mx = 0;
	for (int i = fst; i <= snd; ++i) {
		string r= toRoman(i);
		if (r.length() > mx) {
			mx = r.length();
		}
	}
	cout << mx << endl;
	return 0;
}