#include <bits/stdc++.h>
using namespace std;
int64_t a[11], b[11], c[11];
bool give(int64_t n) {
  vector<int64_t> v;
  while (n != 0) {
    v.push_back(n % 10);
    n /= 10;
  }
  if (v.size() == 1) {
    if (a[v[0]] == 1 or b[v[0]] == 1 or c[v[0]] == 1) return 1;
    return 0;
  }
  if (v.size() == 2) {
    do {
      if (a[v[0]] == 1 and b[v[1]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    do {
      if (b[v[0]] == 1 and c[v[1]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    do {
      if (c[v[0]] == 1 and a[v[1]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    do {
      if (a[v[1]] == 1 and b[v[0]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    do {
      if (b[v[1]] == 1 and c[v[0]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    do {
      if (c[v[1]] == 1 and a[v[0]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    return 0;
  }
  if (v.size() == 3) {
    do {
      if (a[v[0]] == 1 and b[v[1]] == 1 and c[v[2]] == 1) return 1;
    } while (next_permutation((v).begin(), (v).end()));
    return 0;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n;
  cin >> n;
  for (int64_t i = 0; i < n; ++i) {
    for (int64_t j = 0; j < 6; ++j) {
      int64_t x;
      cin >> x;
      if (i == 0)
        a[x] = 1;
      else if (i == 1)
        b[x] = 1;
      else
        c[x] = 1;
    }
  }
  for (int64_t i = 1; i <= 999; ++i)
    if (!give(i)) return cout << i - 1, 0;
}
