#include <bits/stdc++.h>
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const int N = 1100;
const int MAXN = int(1e6) + 100;
const int Mmask = (1 << 20);
const int mod = int(1e9) + 7;
const long long MOD = (long long)(1e18) + 7ll;
int solution();
int main(int argc, char* const argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  return solution();
}
int n, a[4][10];
int solution() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4] >> a[i][5] >> a[i][6];
  }
  for (int i = 1; i <= 9; i++) {
    bool flag = 0;
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= 6; k++)
        if (a[j][k] == i) {
          flag = 1;
          break;
        }
    if (!flag) return cout << i - 1, 0;
  }
  for (int i = 10; i <= 99; i++) {
    bool flag = 0;
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= 6; k++)
        for (int jj = 1; jj <= n; jj++) {
          if (jj == j) continue;
          for (int kk = 1; kk <= 6; kk++)
            if (a[j][k] * 10 + a[jj][kk] == i) {
              flag = 1;
              break;
            }
        }
    if (!flag) return cout << i - 1, 0;
  }
  for (int i = 100; i <= 999; i++) {
    bool flag = 0;
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= 6; k++)
        for (int jj = 1; jj <= n; jj++) {
          if (jj == j) continue;
          for (int kk = 1; kk <= 6; kk++) {
            for (int jjj = 1; jjj <= n; jjj++) {
              if (jjj == jj || jjj == j) continue;
              for (int kkk = 1; kkk <= 6; kkk++)
                if (a[j][k] * 100 + a[jj][kk] * 10 + a[jjj][kkk] == i) {
                  flag = 1;
                  break;
                }
            }
          }
        }
    if (!flag) return cout << i - 1, 0;
  }
  return 0;
}
