#include #include #include #include #include #include #include using namespace std; typedef long long LL; int main(){ int N; cin >> N; vector > num(N); vector judge(N); for(int i = 0; i < N; i++){ int a, b, c, d; cin >> a >> b >> c >> d; num[i].push_back(a); num[i].push_back(b); num[i].push_back(c); num[i].push_back(d); string j; cin >> j; if(j == "YES"){ judge[i] = 1; }else{ judge[i] = 0; } } int ans = -1; for(int i = 0; i <= 9; i++){ bool flag = true; for(int j = 0; j < N; j++){ if(judge[j]){ if(num[j][0] != i && num[j][1] != i && num[j][2] != i && num[j][3] != i){ flag = false; } }else{ if(num[j][0] == i || num[j][1] == i || num[j][2] == i || num[j][3] == i){ flag = false; } } } if(flag){ ans = i; } } cout << ans << endl; return 0; }