#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
bool find(set<long long> s[], vector<long long> v, long long x, long long y,
          long long z) {
  if (v.size() == 1) {
    if (s[x].find(v[0]) != s[x].end()) return true;
  } else if (v.size() == 2) {
    if (s[x].find(v[0]) != s[x].end() && s[y].find(v[1]) != s[y].end())
      return true;
  } else {
    if (s[x].find(v[0]) != s[x].end() && s[y].find(v[1]) != s[y].end() &&
        s[z].find(v[2]) != s[z].end())
      return true;
  }
  return false;
}
void solve() {
  long long n;
  cin >> n;
  set<long long> s[3];
  for (long long i = 0; i < 3; i++) {
    for (long long j = 0; j < 6; j++) {
      long long x;
      cin >> x;
      s[i].insert(x);
    }
  }
  long long ans = 0;
  for (long long i = 1; i < 1000; i++) {
    vector<long long> v;
    long long x = i;
    while (x != 0) {
      v.push_back(x % 10);
      x /= 10;
    }
    bool b = false;
    b |= find(s, v, 0, 1, 2);
    b |= find(s, v, 0, 2, 1);
    b |= find(s, v, 1, 0, 2);
    b |= find(s, v, 1, 2, 0);
    b |= find(s, v, 2, 1, 0);
    b |= find(s, v, 2, 0, 1);
    if (!b) break;
    ans = i;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
}
