#include <bits/stdc++.h>
using namespace std;
int n;
map<int, set<int>> v;
bool check(int x) {
  vector<int> d;
  while (x > 0) {
    d.push_back(x % 10);
    x /= 10;
  }
  if (d.size() == 1) {
    for (int i = 0; i < n; ++i) {
      if (v[i].count(d[0]) > 0) return true;
    }
  }
  if (d.size() == 2) {
    sort(d.begin(), d.end());
    do {
      if (v[0].count(d[0]) > 0 && v[1].count(d[1]) > 0) return true;
      if (v[0].count(d[0]) > 0 && v[2].count(d[1]) > 0) return true;
      if (v[1].count(d[0]) > 0 && v[2].count(d[1]) > 0) return true;
    } while (next_permutation(d.begin(), d.end()));
  }
  if (d.size() == 3) {
    sort(d.begin(), d.end());
    do {
      if (v[0].count(d[0]) > 0 && v[1].count(d[1]) > 0 && v[2].count(d[2]) > 0)
        return true;
    } while (next_permutation(d.begin(), d.end()));
  }
  return false;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 6; ++j) {
        int x;
        cin >> x;
        v[i].insert(x);
      }
    }
    int x = 1;
    while (check(x)) {
      x++;
    }
    cout << x - 1 << '\n';
  }
  return 0;
}
