#include <bits/stdc++.h>
using namespace std;
int d[1005], so[5], luu[1005], pt, mark[5], a[5][15], n;
char temp[16];
void dq(int ln, int tt) {
  int i, j;
  if (tt > ln) {
    int tm, vt, in;
    vt = 0, in = 0;
    for (i = 1; i <= ln; i++) {
      if (so[i] != 0) {
        vt = i;
        break;
      }
    }
    tm = 0;
    for (i = vt; i <= ln; i++) {
      temp[tm++] = so[i] + '0';
    }
    temp[tm] = 0;
    in = atoi(temp);
    if (in > 0 && d[in] == 0) {
      luu[++pt] = in;
      d[in] = 1;
    }
    return;
  }
  for (i = 1; i <= n; i++) {
    if (mark[i] == 0) {
      mark[i] = 1;
      for (j = 1; j <= 6; j++) {
        so[tt] = a[i][j];
        dq(ln, tt + 1);
      }
      mark[i] = 0;
    }
  }
}
void solve() {
  int i, j;
  pt = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 6; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    dq(i, 1);
  }
  sort(luu + 1, luu + pt + 1);
  int maxx = 0;
  for (i = 1; i <= pt; i++) {
    if (luu[i] - 1 != luu[i - 1]) {
      break;
    }
    maxx = luu[i];
  }
  cout << maxx << endl;
}
int main() {
  solve();
  return 0;
}
