#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int f(int x) {
	if (x == 1 || x == 5) return 1;
	if (x == 2 || x == 4 || x == 6 || x == 9) return 2;
	if (x == 3 || x == 7) return 3;
	if (x == 8) return 4;
	return 0;
}

int len(int x) {
	int res = 0;
	while (x) {
		res += f(x%10);
		x /= 10;
	}
	return res;
}

void solve() {
	string s;
	cin >> s;
	size_t del = s.find('-');
	string f = s.substr(0, del);
	string e = s.substr(del+1);
//	cerr << f << ' ' << e << endl;
	
	int fy, ey;
	sscanf(f.substr(0, f.length() - 2).c_str(), "%d", &fy);
	if (f[f.length()-1] == 'C') fy = 753-fy+1;
	else fy = 753+fy;
	sscanf(e.substr(0, e.length() - 2).c_str(), "%d", &ey);
	if (e[e.length()-1] == 'C') ey = 753-ey+1;
	else ey = 753+ey;
	
//	cerr << fy << ' ' << ey << endl;
	
	int res = 0;
	for (int y = fy; y <= ey; ++y)
		res = max(res, len(y));
		
	cout << res << endl;
}

int main() {
	solve();
	
	return 0;
}
