#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
bool ans[10];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c, d;
		string s;
		cin >> a >> b >> c >> d >> s;
		if (s == "NO") {
			ans[a] = true; ans[b] = true; ans[c] = true; ans[d] = true;
		}
		else {
			for (int j = 0; j <= 9; j++) {
				if (j != a && j != b && j != c && j != d)ans[j] = true;
			}
		}
		bool f = false;
		int m;
		for (int j = 0; j <= 9; j++) {
			if (f == true && ans[j] == false)goto age;
			if (ans[j] == false) {
				f = true;
				m = j;
			}
		}
		cout << m << endl;
		break;
	age:;
	}
	return 0;
}