#include <bits/stdc++.h>
using namespace std;
long long n, i, j, ans = 0;
multiset<long long> m[5], M;
void make(long long I, long long J, long long K) {
  if (!K)
    for (auto i : m[I])
      for (auto j : m[J]) M.insert(i * 10 + j), M.insert(j * 10 + i);
  else
    for (auto i : m[I])
      for (auto j : m[J])
        for (auto k : m[K]) M.insert(i * 100 + j * 10 + k);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x;
  cin >> n;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= 6; j++) cin >> x, m[i].insert(x), M.insert(x);
  make(1, 2, 0), make(1, 3, 0), make(3, 2, 0);
  vector<long long> v = {1, 2, 3};
  do {
    make(v[0], v[1], v[2]);
  } while (next_permutation(v.begin(), v.end()));
  for (i = 1; i <= 999; i++)
    if (M.find(i) == M.end()) return cout << i - 1, 0;
}
