#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
inline long long lcm(long long a, long long b) {
  return a * b / max(1LL, gcd(a, b));
}
const long long INF = (long long)1e9 + 2017;
const long long MOD = (long long)1e9 + 7;
const long double EPS = 1e-10;
const long double PI = acos(-1.0);
mt19937 rnd((long long)time(0));
long long arr[3][6];
set<long long> st;
void get1() {
  for (long long i = 0; i < 6; ++i) {
    st.insert(arr[0][i]);
  }
}
void get2() {
  for (long long i = 0; i < 6; ++i) {
    st.insert(arr[0][i]);
    st.insert(arr[1][i]);
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < 6; ++j) {
      st.insert(arr[0][i] * 10 + arr[1][j]);
      st.insert(arr[1][j] * 10 + arr[0][i]);
    }
  }
}
void get3() {
  for (long long i = 0; i < 6; ++i) {
    st.insert(arr[0][i]);
    st.insert(arr[1][i]);
    st.insert(arr[2][i]);
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < 6; ++j) {
      st.insert(arr[0][i] * 10 + arr[1][j]);
      st.insert(arr[1][j] * 10 + arr[0][i]);
    }
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < 6; ++j) {
      st.insert(arr[0][i] * 10 + arr[2][j]);
      st.insert(arr[2][j] * 10 + arr[0][i]);
    }
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < 6; ++j) {
      st.insert(arr[1][i] * 10 + arr[2][j]);
      st.insert(arr[2][j] * 10 + arr[1][i]);
    }
  }
  for (long long i = 0; i < 6; ++i) {
    for (long long j = 0; j < 6; ++j) {
      for (long long k = 0; k < 6; ++k) {
        st.insert(arr[0][i] * 100 + arr[1][j] * 10 + arr[2][k]);
        st.insert(arr[0][i] * 100 + arr[2][k] * 10 + arr[1][j]);
        st.insert(arr[1][j] * 100 + arr[0][i] * 10 + arr[2][k]);
        st.insert(arr[1][j] * 100 + arr[2][k] * 10 + arr[0][i]);
        st.insert(arr[2][k] * 100 + arr[0][i] * 10 + arr[1][j]);
        st.insert(arr[2][k] * 100 + arr[1][j] * 10 + arr[0][i]);
      }
    }
  }
}
vector<long long> ans;
void source() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < 6; ++j) {
      cin >> arr[i][j];
    }
  }
  if (n == 1) {
    get1();
  }
  if (n == 2) {
    get2();
  }
  if (n == 3) {
    get3();
  }
  for (long long i : st) {
    ans.push_back(i);
  }
  if (ans[0] != 1 && ans[1] != 1) {
    cout << 0;
    return;
  }
  for (long long i = 1; i < (long long)(ans).size(); ++i) {
    if (ans[i] != ans[i - 1] + 1) {
      cout << ans[i - 1];
      return;
    }
  }
  cout << ans.back();
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios_base::fixed, ios_base::floatfield);
  cout.precision(10);
  source();
}
