#include <bits/stdc++.h>
using namespace std;
int mark[2000];
int a[5][10];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) mark[a[i][j]] = 1;
  if (n > 1) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j) {
          for (int k = 1; k <= 6; k++) {
            for (int l = 1; l <= 6; l++) {
              if (a[i][k] != 0) mark[a[i][k] * 10 + a[j][l]] = 1;
            }
          }
        }
      }
    }
  }
  if (n > 2) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j) {
          for (int k = 1; k <= n; k++) {
            if (k != i and k != j) {
              for (int l1 = 1; l1 <= 6; l1++) {
                for (int l2 = 1; l2 <= 6; l2++) {
                  for (int l3 = 1; l3 <= 6; l3++) {
                    if (a[i][l1] != 0)
                      mark[a[i][l1] * 100 + a[j][l2] * 10 + a[k][l3]] = 1;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= 1500; i++) {
    if (mark[i])
      cnt++;
    else
      break;
  }
  cout << cnt;
  return 0;
}
