#include <bits/stdc++.h>
using namespace std;
int p[] = {0, 1, 2};
int main() {
  int n;
  cin >> n;
  int input[n][6];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      cin >> input[i][j];
    }
  }
  int max = 0;
  while (true) {
    bool res = false;
    sort(p, p + 3);
    while (true) {
      for (int i = 0; i < pow(6, n); i++) {
        int digits[n];
        string generated = "";
        for (int j = 0; j < n; j++) {
          digits[j] = (int)round(i / (int)pow(6, j)) % 6;
          digits[j] = input[p[j]][digits[j]];
          generated += to_string(digits[j]);
        }
        if (generated.find(to_string(max + 1)) != string::npos) {
          res = true;
          break;
        }
      }
      if (!next_permutation(p, p + n)) break;
    }
    if (!res) {
      break;
    } else {
      max++;
    }
  }
  cout << max << endl;
  return 0;
}
