#include <bits/stdc++.h>
using namespace std;
int v[4][10];
set<int> st;
vector<int> o;
int n;
void calc(int in, int d, int t) {
  if (in == n) {
    if (!t || !d) return;
    st.insert(d);
    return;
  }
  calc(in + 1, d, t);
  for (int i = 0; i < 6; i++) {
    calc(in + 1, d * 10 + v[o[in]][i], t + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    o.push_back(i);
    for (int j = 0; j < 6; j++) {
      scanf("%d", &v[i][j]);
    }
  }
  do {
    calc(0, 0, 0);
  } while (next_permutation(o.begin(), o.end()));
  int c = 1;
  for (auto it = st.begin(); it != st.end(); it++) {
    if (*it == c)
      c++;
    else
      break;
  }
  cout << c - 1 << endl;
  return 0;
}
