#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[4][10];
bool can[900006];
void make2(long long x, long long y) {
  long long ar[10];
  for (long long i = 1; i <= 6; i++) {
    ar[0] = a[x][i];
    long long num = ar[0] * 10;
    for (long long j = 1; j <= 6; j++) {
      ar[1] = a[y][j];
      can[num + ar[1]] = true;
    }
  }
}
void make3(long long x, long long y, long long z) {
  long long ar[10];
  for (long long i = 1; i <= 6; i++) {
    long long num = a[x][i] * 100;
    for (long long j = 1; j <= 6; j++) {
      long long numx = num + a[y][j] * 10;
      for (long long k = 1; k <= 6; k++) {
        can[numx + a[z][k]] = true;
      }
    }
  }
}
long long check() {
  long long i = 0;
  if (can[1] == false) return 0;
  i = 1;
  while (can[i] == true) i++;
  return i - 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 6; j++) {
      cin >> a[i][j];
    }
  }
  if (n == 1) {
    for (long long i = 1; i <= 6; i++) {
      can[a[1][i]] = true;
    }
    long long ans = check();
    cout << ans << endl;
    return 0;
  } else if (n == 2) {
    for (long long i = 1; i <= 6; i++) {
      can[a[1][i]] = true;
    }
    for (long long i = 1; i <= 6; i++) {
      can[a[2][i]] = true;
    }
    make2(1, 2);
    make2(2, 1);
    long long ans = check();
    cout << ans << endl;
    return 0;
  } else if (n == 3) {
    for (long long i = 1; i <= 6; i++) {
      can[a[1][i]] = true;
    }
    for (long long i = 1; i <= 6; i++) {
      can[a[2][i]] = true;
    }
    for (long long i = 1; i <= 6; i++) {
      can[a[3][i]] = true;
    }
    make2(1, 2);
    make2(2, 1);
    make2(1, 3);
    make2(3, 1);
    make2(3, 2);
    make2(2, 3);
    make3(1, 2, 3);
    make3(1, 3, 2);
    make3(2, 1, 3);
    make3(2, 3, 1);
    make3(3, 2, 1);
    make3(3, 1, 2);
    long long ans = check();
    cout << ans << endl;
  }
  return 0;
}
