#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    long long ar[1010] = {0};
    long long i, j, k, pos, in[5][10] = {{0}}, x, y;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= 6; j++) {
        cin >> in[i][j];
      }
    }
    if (n == 1) {
      for (i = 1; i <= 6; i++) {
        x = in[1][i];
        ar[x] = 1;
      }
    } else if (n == 2) {
      for (i = 1; i <= 6; i++) {
        x = in[1][i];
        ar[x] = 1;
        x = in[2][i];
        ar[x] = 1;
        for (j = 1; j <= 6; j++) {
          x = in[1][i] * 10 + in[2][j];
          ar[x] = 1;
          y = in[2][i] * 10 + in[1][j];
          ar[y] = 1;
        }
      }
    } else if (n == 3) {
      for (i = 1; i <= 6; i++) {
        x = in[1][i];
        ar[x] = 1;
        x = in[2][i];
        ar[x] = 1;
        x = in[3][i];
        ar[x] = 1;
        for (j = 1; j <= 6; j++) {
          x = in[1][i] * 10 + in[2][j];
          ar[x] = 1;
          x = in[1][i] * 10 + in[3][j];
          ar[x] = 1;
          x = in[2][i] * 10 + in[1][j];
          ar[x] = 1;
          x = in[2][i] * 10 + in[3][j];
          ar[x] = 1;
          x = in[3][i] * 10 + in[1][j];
          ar[x] = 1;
          x = in[3][i] * 10 + in[2][j];
          ar[x] = 1;
        }
      }
      for (i = 1; i <= 6; i++) {
        for (j = 1; j <= 6; j++) {
          for (k = 1; k <= 6; k++) {
            x = in[1][i] * 100 + in[2][j] * 10 + in[3][k];
            ar[x] = 1;
            x = in[1][i] * 100 + in[3][j] * 10 + in[2][k];
            ar[x] = 1;
            x = in[2][i] * 100 + in[3][j] * 10 + in[1][k];
            ar[x] = 1;
            x = in[2][i] * 100 + in[1][j] * 10 + in[3][k];
            ar[x] = 1;
            x = in[3][i] * 100 + in[1][j] * 10 + in[2][k];
            ar[x] = 1;
            x = in[3][i] * 100 + in[2][j] * 10 + in[1][k];
            ar[x] = 1;
          }
        }
      }
    }
    for (i = 1; i <= 1005; i++) {
      if (ar[i] == 0) {
        pos = i - 1;
        break;
      }
    }
    printf("%I64d\n", pos);
  }
}
