#include <bits/stdc++.h>
using namespace std;
int cube[4][7];
bool possible(int w, int n);
bool exist(int w, int c);
int main() {
  int n;
  scanf("%d", &n);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 6; j++) {
      scanf("%d", &cube[i][j]);
    }
  }
  int mx = 0;
  for (long long i = 1; i <= 999; i++) {
    if (!possible(i, n)) break;
    mx = i;
  }
  printf("%d\n", mx);
}
bool possible(int w, int n) {
  int a, b, c;
  c = w % 10;
  w /= 10;
  b = w % 10;
  w /= 10;
  a = w % 10;
  if (a == 0 && b == 0) {
    return (exist(c, 1)) || exist(c, 2) || exist(c, 3);
  } else if (a == 0) {
    if (n == 1) return false;
    bool z = false || (exist(b, 1) && exist(c, 2));
    z = z || (exist(b, 2) && exist(c, 1));
    if (n == 3) z = z || (exist(b, 1) && exist(c, 3));
    if (n == 3) z = z || (exist(b, 3) && exist(c, 1));
    if (n == 3) z = z || (exist(b, 2) && exist(c, 3));
    if (n == 3) z = z || (exist(b, 3) && exist(c, 2));
    return z;
  } else {
    if (n == 2) return false;
    vector<int> V;
    V.push_back(1);
    V.push_back(2);
    V.push_back(3);
    bool z = (false) || (exist(a, V[0]) && exist(b, V[1]) && exist(c, V[2]));
    while (next_permutation(V.begin(), V.end())) {
      z = z || (exist(a, V[0]) && exist(b, V[1]) && exist(c, V[2]));
    }
    return z;
  }
}
bool exist(int w, int c) {
  for (long long i = 1; i <= 6; i++) {
    if (cube[c][i] == w) return true;
  }
  return false;
}
