#include <bits/stdc++.h>
using namespace std;
int n, a[10][10];
bool mark[1000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) cin >> a[i][j], mark[a[i][j]] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int p = 0; p < 6; p++) {
        for (int pp = 0; pp < 6; pp++) {
          mark[a[i][p] * 10 + a[j][pp]] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int k = 3 - i - j;
      for (int p = 0; p < 6; p++)
        for (int pp = 0; pp < 6; pp++)
          for (int ppp = 0; ppp < 6; ppp++)
            mark[a[i][p] * 100 + a[j][pp] * 10 + a[k][ppp]] = 1;
    }
  }
  for (int i = 1; i < 1000; i++)
    if (!mark[i]) {
      cout << i - 1 << endl;
      return 0;
    }
}
