#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > a;
int res[1000];
int perm[3] = {0, 1, 2};
void init() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    a[i].resize(6);
    for (int j = 0; j < 6; ++j) cin >> a[i][j];
  }
}
void f(int cnt, int number) {
  if (cnt == 1 && number == 0) return;
  res[number] = 1;
  if (cnt == n) return;
  int arrNumber = perm[cnt];
  for (int i = 0; i < 6; ++i) f(cnt + 1, number * 10 + a[arrNumber][i]);
}
void solve() {
  do {
    f(0, 0);
  } while (std::next_permutation(perm, perm + n));
  for (int i = 1; i <= 1000; ++i) {
    if (res[i] == 0) {
      cout << i - 1;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  init();
  solve();
  return 0;
}
