#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  set<int> s;
  vector<vector<int>> a(n);
  for (int j = 0; j < n; ++j)
    for (int i = 0, x; i < 6; ++i) {
      cin >> x;
      a[j].push_back(x);
    }
  vector<int> idx(n);
  function<void(int, int)> f = [&](int p, int x) {
    if (p > 0) s.insert(x);
    if (p == n) return;
    for (auto i : a[idx[p]])
      if (p != 0 || i > 0) f(p + 1, x * 10 + i);
  };
  iota(idx.begin(), idx.end(), 0);
  do {
    f(0, 0);
  } while (next_permutation(idx.begin(), idx.end()));
  for (int i = 1;; ++i)
    if (s.find(i) == s.end()) {
      cout << i - 1 << "\n";
      break;
    }
  return 0;
}
