#include <bits/stdc++.h>
using namespace std;
const int M = 10;
set<int> s[M];
int n, p[M];
bool check(int x) {
  vector<int> b;
  while (x) {
    b.push_back(x % 10);
    x /= 10;
  }
  if (b.size() > n) return false;
  for (int i = 0; i < b.size(); i++)
    if (s[p[i]].find(b[i]) == s[p[i]].end()) return false;
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    p[i] = i;
    for (int j = 0; j < 6; j++) {
      int x;
      cin >> x;
      s[i].insert(x);
    }
  }
  for (int x = 1;; x++) {
    int fnd = false;
    for (int i = 0; i < n; i++) p[i] = i;
    do {
      if (check(x)) fnd = true;
    } while (next_permutation(p, p + n));
    if (!fnd) return cout << x - 1 << endl, 0;
  }
  return 0;
}
