#include <bits/stdc++.h>
using namespace std;
set<int> pos;
int n;
vector<vector<int>> cubes(3);
inline void fill2(int a, int b, int c) {
  if (a < cubes[0].size() && b < cubes[1].size()) {
    pos.insert(10 * cubes[0][a] + cubes[1][b]);
    pos.insert(10 * cubes[1][b] + cubes[0][a]);
  }
  if (a < cubes[0].size() && c < cubes[2].size()) {
    pos.insert(10 * cubes[0][a] + cubes[2][c]);
    pos.insert(10 * cubes[2][c] + cubes[0][a]);
  }
  if (c < cubes[2].size() && b < cubes[1].size()) {
    pos.insert(10 * cubes[1][b] + cubes[2][c]);
    pos.insert(10 * cubes[2][c] + cubes[1][b]);
  }
  if (c + 1 < cubes[2].size()) fill2(a, b, c + 1);
  if (b + 1 < cubes[1].size()) fill2(a, b + 1, c);
  if (a + 1 < cubes[0].size()) fill2(a + 1, b, c);
}
inline void fill3(int a, int b, int c) {
  if (a < cubes[0].size() && b < cubes[1].size() && c < cubes[2].size()) {
    pos.insert(100 * cubes[0][a] + 10 * cubes[1][b] + cubes[2][c]);
    pos.insert(100 * cubes[0][a] + 10 * cubes[2][c] + cubes[1][b]);
    pos.insert(100 * cubes[1][b] + 10 * cubes[0][a] + cubes[2][c]);
    pos.insert(100 * cubes[1][b] + 10 * cubes[2][c] + cubes[0][a]);
    pos.insert(100 * cubes[2][c] + 10 * cubes[0][a] + cubes[1][b]);
    pos.insert(100 * cubes[2][c] + 10 * cubes[1][b] + cubes[0][a]);
    if (c != cubes[2].size() - 1) fill3(a, b, c + 1);
    if (b != cubes[1].size() - 1) fill3(a, b + 1, c);
    if (a != cubes[0].size() - 1) fill3(a + 1, b, c);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 6; ++j) {
      int a;
      cin >> a;
      cubes[i].push_back(a);
      pos.insert(a);
    }
    std::vector<int>::iterator it =
        std::unique(cubes[i].begin(), cubes[i].end());
    cubes[i].resize(std::distance(cubes[i].begin(), it));
  }
  pos.erase(0);
  int max = 1;
  for (auto it = pos.begin(); it != pos.end(); it++) {
    if (*it == max)
      max++;
    else
      break;
  }
  if (max == 10 && n > 1) {
    max = 1;
    fill2(0, 0, 0);
    pos.erase(0);
    for (auto it = pos.begin(); it != pos.end(); it++) {
      if (*it == max)
        max++;
      else
        break;
    }
    if (max == 100 && n == 3) {
      max = 1;
      fill3(0, 0, 0);
      pos.erase(0);
      for (auto it = pos.begin(); it != pos.end(); it++) {
        if (*it == max)
          max++;
        else
          break;
      }
    }
  }
  cout << max - 1;
  return 0;
}
