#include <bits/stdc++.h>
using namespace std;
int x[4][10];
int n;
bool check(int);
int main() {
  int i, j, k, ans;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= 6; j++) scanf("%d", &x[i][j]);
  ans = 0;
  for (i = 1; i < 1000; i++)
    if (check(i))
      ans = i;
    else
      break;
  printf("%d", ans);
  return 0;
}
bool check(int zz) {
  int i, j, k;
  if (zz / 10 == 0) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= 6; j++)
        if (x[i][j] == zz) return true;
    return false;
  }
  if (zz / 100) {
    int a, b, c, pa, pb, pc, wha[3], whb[3], whc[3], i, j, k;
    memset(wha, 0, sizeof(wha));
    memset(whb, 0, sizeof(whb));
    memset(whc, 0, sizeof(whc));
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= 6; j++) {
        if (x[i][j] == (zz / 10) % 10 && pa == 0) a++, pa = 1, wha[i - 1] = 1;
        if (x[i][j] == zz % 10 && pb == 0) b++, pb = 1, whb[i - 1] = 1;
        if (x[i][j] == zz / 100 && pc == 0) c++, pc = 1, whc[i - 1] = 1;
      }
      pa = pb = pc = 0;
    }
    if (a == 0 || b == 0 || c == 0) return false;
    if ((wha[0] && whb[1] && whc[2])) return true;
    if ((wha[0] && whb[2] && whc[1])) return true;
    if ((wha[1] && whb[0] && whc[2])) return true;
    if ((wha[1] && whb[2] && whc[0])) return true;
    if ((wha[2] && whb[0] && whc[1])) return true;
    if ((wha[2] && whb[1] && whc[0])) return true;
    return false;
  }
  int a = 0, b = 0, pa = 0, pb = 0, wha, whb;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 6; j++) {
      if (x[i][j] == zz / 10 && pa == 0) a++, pa = 1, wha = i;
      if (x[i][j] == zz % 10 && pb == 0) b++, pb = 1, whb = i;
    }
    pa = pb = 0;
  }
  if (a == 0 || b == 0) return false;
  if (a > 1 || b > 1) return true;
  return wha != whb;
}
