#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  unordered_map<long long, set<long long>> mp;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 0; j < 6; ++j) {
      long long a;
      cin >> a;
      mp[a].insert(i);
    }
  }
  long long a = 1;
  while (1) {
    if (a < 10 && mp[a].size())
      a++;
    else {
      set<long long> st1 = mp[a % 10];
      set<long long> st2 = mp[a / 10];
      if (st1.size() == 0 || st2.size() == 0) break;
      if (st1.size() == 1 && st1 == st2) break;
      a++;
    }
  }
  cout << a - 1 << endl;
}
