// #pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <set>

using namespace std;

#define mp make_pair
#define ll long long
#define pb push_back

vector<string> splitString(string str) {
	stringstream ss(str);

	string s;
	vector<string> v;
	while (getline(ss, s, '-')) {
		v.push_back(s);
	}

	return v;
}

int convertToInt(string s) {
	stringstream ss(s);
	int v;
	ss >> v;
	return v;
}

map<char, bool> ans;

int main() {
	string str;
	cin >> str;

	vector<string> v = splitString(str);

	int a = convertToInt(v[0].substr(0, v[0].length() - 2));
	int b = convertToInt(v[1].substr(0, v[1].length() - 2));

	if (v[0][v[0].length() - 2] == 'B') {
		a = 754 - a;
	}
	else {
		a += 753;
	}

	if (v[1][v[1].length() - 2] == 'B') {
		b = 754 - b;
	}
	else {
		b += 753;
	}

	int mx = 0;
	for (int i = a; i <= b; i++) {
		int t = i;
		int curr = 0;
		// 1000
		int x = t / 1000;
		if (x > 0) {
			if (x <= 3) {
				ans['M'] = true;
				curr += x;
			}
		}
		t %= 1000;

		// 100
		x = t / 100;
		if (x > 0) {
			if (x <= 3) {
				ans['C'] = true;
				curr += x;
			}
			else if (x == 4) {
				ans['C'] = true;
				ans['D'] = true;
				curr += 2;
			}
			else if (x == 5) {
				ans['D'] = true;
				curr++;
			}
			else if (x <= 8) {
				ans['D'] = true;
				ans['C'] = true;
				curr += x - 4;
			}
			else if (x == 9) {
				ans['C'] = true;
				ans['M'] = true;
				curr += 2;
			}
		}
		t %= 100;
		// 10

		x = t / 10;
		if (x > 0) {
			if (x <= 3) {
				ans['X'] = true;
				curr += x;
			}
			else if (x == 4) {
				ans['X'] = true;
				ans['L'] = true;
				curr += 2;
			}
			else if (x == 5) {
				ans['L'] = true;
				curr++;
			}
			else if (x <= 8) {
				ans['L'] = true;
				ans['X'] = true;
				curr += x - 4;
			}
			else if (x == 9) {
				ans['X'] = true;
				ans['C'] = true;
				curr += 2;
			}
		}
		t %= 10;

		// 1
		x = t;
		if (x > 0) {
			if (x <= 3) {
				ans['I'] = true;
				curr += x;
			}
			else if (x == 4) {
				ans['I'] = true;
				ans['V'] = true;
				curr += 2;
			}
			else if (x == 5) {
				ans['V'] = true;
				curr++;
			}
			else if (x <= 8) {
				ans['V'] = true;
				ans['I'] = true;
				curr += x - 4;
			}
			else if (x == 9) {
				ans['I'] = true;
				ans['X'] = true;
				curr += 2;
			}
		}

		mx = max(curr, mx);
	}

	cout << mx << endl;

	return 0;
}
/*
753BC-753BC
2012AD-2012AD

753BC-747BC
1BC-1AD
2000AD-2012AD
*/