#include "bits/stdc++.h" #define REP(i,n) for(ll i=0;i=0;--i) #define FOR(i,m,n) for(ll i=m;i=ll(m);--i) #define ALL(v) (v).begin(),(v).end() #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); #define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = { 1,1,0,-1,-1,-1,0,1 }; const int dy[8] = { 0,1,1,1,0,-1,-1,-1 }; using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef vector vvi; typedef vector vvl; typedef pair pii; typedef pair pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)/// int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vi y, n; int f = 0; REP(i, N) { vi tmp(4); REP(j, 4)cin >> tmp[j]; string s; cin >> s; if (s[0] == 'Y') { vi next; REP(j, y.size()) { REP(k, tmp.size()) { if (y[j] == tmp[k])next.push_back(y[j]); } } if (!f)y = tmp; else y = next; f = 1; } else { REP(j, 4)n.push_back(tmp[j]); } } sort(ALL(y)); sort(ALL(n)); UNIQUE(y); UNIQUE(n); if (n.size() == 9) { REP(i, 10) { int f = 0; REP(j, 9) { if (n[j] == i)f = 1; } if (!f) { cout << i << endl; return 0; } } } REP(i, 10) { int c = lower_bound(ALL(y), i) - y.begin(); if (c != y.size() && y[c] == i) { int d = lower_bound(ALL(n), i) - n.begin(); if(d==n.size()||n[d]!=i){ cout << i << endl; return 0; } } } }