#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 9;
long long base = 33;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<set<long long>> mas(n);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 6; j++) {
      long long k;
      cin >> k;
      mas[i].insert(k);
    }
  }
  for (long long i = 1; i < 1000; i++) {
    bool ok = 0;
    vector<long long> a(n);
    for (long long j = 0; j < n; j++) a[j] = j;
    do {
      long long ans = i;
      bool ok1 = 1;
      for (long long j = 0; j < n; j++) {
        if (ans == 0) break;
        long long p = ans % 10;
        ans /= 10;
        if (!mas[a[j]].count(p)) ok1 = 0;
      }
      if (ans == 0 && ok1) {
        ok = 1;
        break;
      }
    } while (next_permutation(a.begin(), a.end()));
    if (!ok) {
      cout << i - 1;
      return 0;
    }
  }
  return 0;
}
