#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  int f = 0;
  vector<vector<int> > A(4, vector<int>(10, 0));
  for (int i = 0; i < n; i++) {
    f = 0;
    for (int j = 0; j < 6; j++) {
      cin >> a;
      A[i][a] = 1;
    }
  }
  int maxi = 0, x, g = 0;
  vector<int> B, C(3, 0);
  int z = pow(10, n);
  for (int i = 1; i < z; i++) {
    x = i;
    B.clear();
    while (x > 0) {
      B.push_back(x % 10);
      x /= 10;
    }
    f = 0;
    g = 0;
    for (int k = 0; k < 3; k++) {
      C[0] = k;
      for (int j = 0; j < 3; j++) {
        C[1] = j;
        for (int l = 0; l < 3; l++) {
          C[2] = l;
          if (k != j && k != l && j != l) {
            g = 1;
            for (int m = 0; m < B.size(); m++) {
              if (A[C[m]][B[m]] == 0) {
                g = 0;
                break;
              }
            }
            if (g == 1) {
              f = 1;
              break;
            }
          }
        }
      }
    }
    if (f == 0) {
      break;
    } else {
      maxi = i;
    }
  }
  cout << maxi << endl;
  return 0;
}
