#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 1000;
int n;
set<int> s[4];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int tmp;
    for (int j = 1; j <= 6; j++) cin >> tmp, s[i].insert(tmp);
  }
  int i;
  for (i = 1; i <= MAXN; i++) {
    if (i == MAXN) break;
    multiset<int> ms;
    int t = i;
    while (t > 0) {
      ms.insert(t % 10);
      t /= 10;
    }
    for (int j = 1; j <= n; j++) {
      for (auto x : ms)
        if (s[j].count(x) > 0) {
          ms.erase(ms.find(x));
          break;
        }
    }
    if (ms.empty()) continue;
    ms.clear();
    t = i;
    while (t > 0) {
      ms.insert(t % 10);
      t /= 10;
    }
    for (int j = n; j > 0; j--) {
      for (auto x : ms)
        if (s[j].count(x) > 0) {
          ms.erase(ms.find(x));
          break;
        }
    }
    if (ms.empty()) continue;
    break;
  }
  cout << i - 1;
  return 0;
}
