#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > arr;
bool flag = false;
int n;
void recurse(int index, int val, int target) {
  if (val > target) return;
  if (val == target) {
    flag = true;
    return;
  }
  if (index >= n) return;
  for (int i = 0; i < 6; ++i) {
    int temp = val;
    temp = (temp * 10) + arr[index][i];
    recurse(index + 1, temp, target);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    vector<int> temp(6);
    for (int j = 0; j < 6; ++j) {
      cin >> temp[j];
    }
    arr.push_back(temp);
  }
  int a = 0;
  for (int num = 0; num <= 999; ++num) {
    flag = false;
    vector<int> temp;
    for (int i = 0; i < n; ++i) temp.push_back(i + 1);
    vector<vector<int> > t = arr;
    do {
      for (int i = 0; i < n; ++i) {
        arr[i] = t[temp[i] - 1];
      }
      recurse(0, 0, num);
      arr = t;
      if (flag == true) break;
    } while (next_permutation(temp.begin(), temp.end()));
    arr = t;
    if (flag == false) break;
    a++;
  }
  a = max(0, a - 1);
  cout << a << '\n';
}
