#include <bits/stdc++.h>
using namespace std;
const int L = 100010;
bool a[4][7];
;
bool vis[120];
int n;
int main() {
  scanf("%d", &n);
  int i, j;
  memset(vis, false, sizeof(vis));
  for (i = 0; i < n; i++) {
    for (j = 0; j < 6; j++) scanf("%d", &a[i][j]);
  }
  int I, J, t;
  for (i = 0; i < n; i++) {
    for (j = 0; j < 6; j++) {
      t = a[i][j] * 10;
      vis[a[i][j]] = true;
      for (I = 0; I < n; I++) {
        if (i == I) continue;
        for (J = 0; J < 6; J++) {
          t = a[i][j] * 10;
          t += a[I][J];
          vis[t] = true;
        }
      }
    }
  }
  for (i = 1; i < 100; i++) {
    while (vis[i]) i++;
    if (i == 99 && vis[99])
      printf("%d\n", 99);
    else
      printf("%d\n", i - 1);
    break;
  }
  return 0;
}
