#include <bits/stdc++.h>
using namespace std;
int n, tot = 1;
int a[4][7], f[10000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) {
      scanf("%d", &a[i][j]);
      f[a[i][j]] = 1;
    }
  if (n == 2)
    for (int i = 1; i <= 6; i++)
      for (int j = 1; j <= 6; j++) {
        f[a[1][i] * 10 + a[2][j]] = 1;
        f[a[2][j] * 10 + a[1][i]] = 1;
      }
  if (n == 3) {
    for (int i = 1; i <= 6; i++)
      for (int j = 1; j <= 6; j++) {
        f[a[1][i] * 10 + a[2][j]] = 1;
        f[a[2][j] * 10 + a[1][i]] = 1;
      }
    for (int i = 1; i <= 6; i++)
      for (int j = 1; j <= 6; j++) {
        f[a[2][i] * 10 + a[3][j]] = 1;
        f[a[3][j] * 10 + a[2][i]] = 1;
      }
    for (int i = 1; i <= 6; i++)
      for (int j = 1; j <= 6; j++) {
        f[a[1][i] * 10 + a[3][j]] = 1;
        f[a[3][j] * 10 + a[1][i]] = 1;
      }
  }
  while (f[tot]) tot++;
  cout << --tot;
  return 0;
}
