#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<bool>> used(3, vector<bool>(10, false));
bool check(int x, int n) {
  vector<int> a, perm(n);
  while (x) {
    a.push_back(x % 10);
    x /= 10;
  }
  if ((int)a.size() > n) return false;
  for (int i = 0; i < n; i++) perm[i] = i;
  bool ok = false;
  do {
    bool f = true;
    for (int i = 0; i < (int)a.size(); i++)
      if (!used[perm[i]][a[i]]) f = false;
    if (f) ok = true;
  } while (next_permutation(perm.begin(), perm.end()));
  return ok;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 6; j++) {
      int val;
      cin >> val;
      used[i][val] = true;
    }
  int ans = 1;
  for (;;) {
    if (!check(ans, n)) {
      cout << ans - 1 << endl;
      return 0;
    }
    ans++;
  }
  return 0;
}
