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8 6 4
 3
2 3 4 5 6 7
3 4 5 6 7 8
9 1 2 3 4 5
 2
0 1 2 3 4 5
4 5 6 7 8 9
 3
2 7 3 6 4 5
0 2 1 9 4 8
8 6 9 5 4 0
 2
0 1 2 3 4 5
6 7 8 9 6 6
 2
1 7 2 0 4 3
5 2 3 6 1 0
 1
6 2 8 5 1 3
 3
5 4 8 1 6 7
0 9 3 5 8 6
2 4 7 8 1 3
 1
6 3 1 9 4 9
 3
0 1 9 1 0 8
9 9 3 5 6 2
9 3 9 9 7 3
 3
8 1 6 8 6 8
7 0 2 5 8 4
5 2 0 3 1 9
 3
2 0 1 3 4 5
6 7 8 9 1 1
3 4 5 6 6 7
 3
4 4 5 0 6 6
7 1 6 9 5 4
5 0 4 0 3 9
 2
0 1 2 3 4 5
9 8 7 6 5 4
 2
0 2 9 1 8 5
0 7 4 3 2 5
 2
2 3 9 1 6 7
2 5 4 3 0 6
 2
5 7 4 2 1 9
2 2 7 1 1 8
 1
3 9 1 7 4 5
 3
7 7 2 5 3 2
3 0 0 6 4 4
1 2 1 1 9 1
 1
7 9 5 0 4 6
 3
7 1 3 0 2 4
2 4 3 0 9 5
1 9 8 0 6 5
 1
4 3 8 9 2 3

3
 9
 9
 4
 2
 10
 10
 1
 4
 0
 2
 5
 0
 8
 2
 2
 10
 19
 3
 3
 2
 0
 5
 19
 3
 2
 1
 2
 1
 4
 2
 9
 5
 8
 1
 10
 7
 0
 5
 4
 3
 5
 9
 9
 29
 0
 0
 1
 8
 9
 21
 6
 21
 1
 8
 6
 1
 21
 6
 3
 2
 0
 0
 1
 0
 0
 0
 2
 0
 3
 0
 98
 2
 9
 9
 10
 9
 7
 3
 21
 1
 3
 32
 19
 1
 9
 5
 7
 2
 1
 7
 0
 65
 0

#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 45LL);
const long long MAXLL = 9223372036854775807LL;
const unsigned long long MAXULL = 18446744073709551615LLU;
const long long MOD = 1000000007;
const long double DELTA = 0.000000001L;
inline long long fmm(long long a, long long b, long long m = MOD) {
  long long r = 0;
  a %= m;
  b %= m;
  while (b > 0) {
    if (b & 1) {
      r += a;
      r %= m;
    }
    a += a;
    a %= m;
    b >>= 1;
  }
  return r % m;
}
inline long long fme(long long a, long long b, long long m = MOD) {
  long long r = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) {
      r *= a;
      r %= m;
    }
    a *= a;
    a %= m;
    b >>= 1;
  }
  return r % m;
}
inline long long sfme(long long a, long long b, long long m = MOD) {
  long long r = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) r = fmm(r, a, m);
    a = fmm(a, a, m);
    b >>= 1;
  }
  return r % m;
}
std::vector<long long> primes;
long long primsiz;
std::vector<long long> fact;
std::vector<long long> invfact;
inline void sieve(long long n) {
  long long i, j;
  std::vector<bool> a(n);
  a[0] = true;
  a[1] = true;
  for (i = 2; i * i < n; ++i) {
    if (!a[i]) {
      for (j = i * i; j < n; j += i) {
        a[j] = true;
      }
    }
  }
  for (i = 2; i < n; ++i)
    if (!a[i]) primes.push_back(i);
  primsiz = primes.size();
}
inline void sieve() {
  long long n = 1010000, i, j, k = 0;
  std::vector<bool> a(n);
  primes.resize(79252);
  a[0] = a[1] = true;
  for (i = 2; (j = (i << 1)) < n; ++i) a[j] = true;
  for (i = 3; i * i < n; i += 2) {
    if (!a[i]) {
      k = (i << 1);
      for (j = i * i; j < n; j += k) a[j] = true;
    }
  }
  k = 0;
  for (i = 2; i < n; ++i)
    if (!a[i]) primes[k++] = i;
  primsiz = k;
}
inline bool isPrimeSmall(unsigned long long n) {
  if (((!(n & 1)) && n != 2) || (n < 2) || (n % 3 == 0 && n != 3)) return false;
  for (unsigned long long k = 1; 36 * k * k - 12 * k < n; ++k)
    if ((n % (6 * k + 1) == 0) || (n % (6 * k - 1) == 0)) return false;
  return true;
}
bool _p(unsigned long long a, unsigned long long n) {
  unsigned long long t, u, i, p, c = 0;
  u = n / 2, t = 1;
  while (!(u & 1)) {
    u /= 2;
    ++t;
  }
  p = fme(a, u, n);
  for (i = 1; i <= t; ++i) {
    c = (p * p) % n;
    if ((c == 1) && (p != 1) && (p != n - 1)) return 1;
    p = c;
  }
  if (c != 1) return 1;
  return 0;
}
inline bool isPrime(unsigned long long n) {
  if (((!(n & 1)) && n != 2) || (n < 2) || (n % 3 == 0 && n != 3)) return 0;
  if (n < 1373653) {
    for (unsigned long long k = 1; (((36 * k * k) - (12 * k)) < n); ++k)
      if ((n % (6 * k + 1) == 0) || (n % (6 * k - 1) == 0)) return 0;
    return 1;
  }
  if (n < 9080191) {
    if (_p(31, n) || _p(73, n)) return 0;
    return 1;
  }
  if (_p(2, n) || _p(7, n) || _p(61, n)) return 0;
  return 1;
}
unsigned long long nCk(long long n, long long k, unsigned long long m = MOD) {
  if (k < 0 || k > n || n < 0) return 0;
  if (k == 0 || k == n) return 1;
  if (fact.size() >= (unsigned long long)n && isPrime(m)) {
    return (((fact[n] * invfact[k]) % m) * invfact[n - k]) % m;
  }
  unsigned long long i = 0, j = 0, a = 1;
  k = ((k) < (n - k) ? (k) : (n - k));
  for (; i < (unsigned long long)k; ++i) {
    a = (a * (n - i)) % m;
    while (j < (unsigned long long)k && (a % (j + 1) == 0)) {
      a = a / (j + 1);
      ++j;
    }
  }
  while (j < (unsigned long long)k) {
    a = a / (j + 1);
    ++j;
  }
  return a % m;
}
void nCkInit(unsigned long long m = MOD) {
  long long i, mx = 1010000;
  fact.resize(mx + 1);
  invfact.resize(mx + 1);
  fact[0] = 1;
  for (i = 1; i <= mx; ++i) {
    fact[i] = (i * fact[i - 1]) % m;
  }
  invfact[mx] = fme(fact[mx], m - 2, m);
  for (i = mx - 1; i >= 0; --i) {
    invfact[i] = (invfact[i + 1] * (i + 1)) % m;
  }
}
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  long long x1, y1;
  extGCD(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
}
inline void get(long long &x) {
  int n = 0;
  x = 0;
  char c = getchar_unlocked();
  if (c == '-') n = 1;
  while (c < '0' || c > '9') {
    c = getchar_unlocked();
    if (c == '-') n = 1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar_unlocked();
  }
  if (n) x = -x;
}
inline int get(char *p) {
  char c = getchar_unlocked();
  int i = 0;
  while (c != '\n' && c != '\0' && c != ' ' && c != '\r' && c != EOF) {
    p[i++] = c;
    c = getchar_unlocked();
  }
  p[i] = '\0';
  return i;
}
inline void put(long long a) {
  int n = (a < 0 ? 1 : 0);
  if (n) a = -a;
  char b[20];
  int i = 0;
  do {
    b[i++] = a % 10 + '0';
    a /= 10;
  } while (a);
  if (n) putchar_unlocked('-');
  i--;
  while (i >= 0) putchar_unlocked(b[i--]);
  putchar_unlocked(' ');
}
inline void putln(long long a) {
  int n = (a < 0 ? 1 : 0);
  if (n) a = -a;
  char b[20];
  int i = 0;
  do {
    b[i++] = a % 10 + '0';
    a /= 10;
  } while (a);
  if (n) putchar_unlocked('-');
  i--;
  while (i >= 0) putchar_unlocked(b[i--]);
  putchar_unlocked('\n');
}
const int K = 3;
std::vector<std::vector<long long> > mul(std::vector<std::vector<long long> > a,
                                         std::vector<std::vector<long long> > b,
                                         unsigned long long m = MOD) {
  std::vector<std::vector<long long> > c(K, std::vector<long long>(K));
  for (long long ii = 0; ii < (K); ++ii)
    for (long long jj = 0; jj < (K); ++jj)
      for (long long kk = 0; kk < (K); ++kk)
        c[ii][jj] = (c[ii][jj] + a[ii][kk] * b[kk][jj]) % m;
  return c;
}
std::vector<std::vector<long long> > fme(std::vector<std::vector<long long> > a,
                                         unsigned long long n,
                                         unsigned long long m = MOD) {
  if (n == 1) return a;
  if (n & 1) return mul(a, fme(a, n - 1, m), m);
  std::vector<std::vector<long long> > x = fme(a, n / 2, m);
  return mul(x, x, m);
}
set<long long> s[4];
bool ok(long long n, long long x) {
  if (x < 10) {
    for (long long i = 0; i < (n); ++i)
      if (s[i].count(x)) return true;
    return false;
  } else if (x < 100) {
    long long f = (x % 10);
    x /= 10;
    for (long long i = 0; i < (n); ++i) {
      for (long long j = 0; j < (n); ++j) {
        if (i == j) continue;
        if (s[i].count(f) && s[j].count(x)) return true;
      }
    }
    return false;
  } else {
    long long f = (x % 10);
    x /= 10;
    long long g = (x % 10);
    x /= 10;
    for (long long i = 0; i < (n); ++i) {
      for (long long j = 0; j < (n); ++j) {
        for (long long k = 0; k < (n); ++k) {
          if (i == j || j == k || i == k) continue;
          if (s[i].count(f) && s[j].count(g) && s[k].count(x)) return true;
        }
      }
    }
    return false;
  }
  return false;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  long long t = 0, n = 0, m = 0, maxx = 0, minn = 0, curr = 0, k = 0, num = 0,
            siz = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0, ind = 0;
  long long root = 0, sum = 0, diff = 0, q = 0, choice = 0, d = 0, len = 0,
            begg = 0, endd = 0, pos = 0, cnt = 0, lo = 0, hi = 0, mid = 0,
            ans = 0;
  bool flag = false;
  std::string s1, s2, s3, str;
  char ch, ch1, ch2, ch3, *ptr;
  double dub = 0;
  cin >> n;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (6); ++j) {
      cin >> k;
      s[i].insert(k);
    }
  }
  for (long long i = 1; i <= (1001); ++i) {
    if (!ok(n, i)) {
      cout << (i - 1);
      break;
    }
  }
  return 0;
}
