#include using namespace std; int main() { int n; cin >> n; set no; vector, pair>> val; for (int i = 0; i < n; i++) { int a, b, c, d; string s; cin >> a >> b >> c >> d >> s; if (s == "YES") { val.emplace_back(make_pair(a, b), make_pair(c, d)); } else { for (int e : {a, b, c, d}) no.emplace(e); } } int ans = 0; for (int i = 0; i < 10; i++) { if (no.count(i)) continue; bool ok = true; for (const auto &e : val) { int a, b, c, d; tie(a, b) = e.first; tie(c, d) = e.second; ok &= (a == i or b == i or c == i or d == i); } if (ok) { ans = i; break; } } cout << ans << '\n'; return 0; }