#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t n;
  cin >> n;
  array<vector<size_t>, 10> digits;
  for (size_t cube = 0; cube < n; ++cube) {
    for (size_t i = 0; i < 6; ++i) {
      size_t tmp;
      cin >> tmp;
      if (digits[tmp].empty() || digits[tmp].back() != cube)
        digits[tmp].push_back(cube);
    }
  }
  for (size_t x = 1; x < 1000; ++x) {
    size_t rest = x;
    array<size_t, 3> xDigits;
    fill(xDigits.begin(), xDigits.end(), -1);
    size_t curDigit = 0;
    for (size_t d = rest % 10;; d = rest % 10) {
      rest /= 10;
      xDigits[curDigit++] = d;
      if (rest == 0) break;
    }
    bool can = false;
    array<bool, 3> usedCubes = {false, false, false};
    for (auto cube1 : digits[xDigits[0]]) {
      usedCubes[cube1] = true;
      if (curDigit > 1) {
        for (auto cube2 : digits[xDigits[1]]) {
          if (!usedCubes[cube2]) {
            usedCubes[cube2] = true;
            if (curDigit > 2) {
              for (auto cube3 : digits[xDigits[2]]) {
                if (!usedCubes[cube3]) {
                  can = true;
                  break;
                }
              }
            } else {
              can = true;
            }
            usedCubes[cube2] = false;
            if (can) break;
          }
        }
      } else {
        can = true;
      }
      usedCubes[cube1] = false;
      if (can) break;
    }
    if (!can) {
      cout << x - 1 << endl;
      break;
    }
  }
  return 0;
}
