#include <bits/stdc++.h>
using namespace std;
int N, ok, k;
int fr[10], v[5];
int apar[5][10], rsp[5][5];
void bk(int poz) {
  if (poz > N) {
    k++;
    for (int i = 1; i <= N; i++) rsp[k][i] = v[i];
    return;
  }
  for (int i = 1; i <= N; i++) {
    if (fr[i] == 0) {
      fr[i] = 1;
      v[poz] = i;
      bk(poz + 1);
      fr[i] = 0;
    }
  }
}
int checker(int nr, int id) {
  int i = 1;
  while (nr > 0) {
    if (apar[rsp[id][i]][nr % 10] == 0) return 0;
    i++;
    nr /= 10;
  }
  return 1;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j < 6; j++) {
      int a;
      cin >> a;
      apar[i][a] = 1;
    }
  for (int i = 1; i <= N; i++) fr[i] = 0;
  bk(1);
  for (int nr = 1; nr <= 999; nr++) {
    int ok = 0;
    for (int i = 1; i <= k; i++)
      if (checker(nr, i) == 1) {
        ok = 1;
        break;
      }
    if (ok == 0) {
      cout << nr - 1 << "\n";
      return 0;
    }
  }
  return 0;
}
