#include <bits/stdc++.h>
using namespace std;
int arr[3][6];
bool res[1000];
map<int, int> nums;
int main() {
  int n;
  scanf("%d", &n) == 0;
  for (decltype(0) i = 0; i < n; i++) {
    for (decltype(0) j = 0; j < 6; j++) {
      char c;
      scanf(" %c", &c) == 0;
      arr[i][j] = c - '0';
      nums[arr[i][j]]++;
    }
  }
  for (decltype(0) i = 0; i < 7; i++) {
    for (decltype(0) j = 0; j < 7; j++) {
      for (decltype(0) k = 0; k < 7; k++) {
        int a = 0;
        if (i != 6) a += arr[0][i];
        if (j != 6 && n > 1) a = a * 10 + arr[1][j];
        if (k != 6 && n > 2) a = a * 10 + arr[2][k];
        res[a] = 1;
        a = 0;
        if (i != 6) a += arr[0][i];
        if (k != 6 && n > 2) a = a * 10 + arr[2][k];
        if (j != 6 && n > 1) a = a * 10 + arr[1][j];
        res[a] = 1;
        a = 0;
        if (j != 6 && n > 1) a += arr[1][j];
        if (i != 6) a = a * 10 + arr[0][i];
        if (k != 6 && n > 2) a = a * 10 + arr[2][k];
        res[a] = 1;
        a = 0;
        if (j != 6 && n > 1) a += arr[1][j];
        if (k != 6 && n > 2) a = a * 10 + arr[2][k];
        if (i != 6) a = a * 10 + arr[0][i];
        res[a] = 1;
        a = 0;
        if (k != 6 && n > 2) a += arr[2][k];
        if (i != 6) a = a * 10 + arr[0][i];
        if (j != 6 && n > 1) a = a * 10 + arr[1][j];
        res[a] = 1;
        a = 0;
        if (k != 6 && n > 2) a += arr[2][k];
        if (j != 6 && n > 1) a = a * 10 + arr[1][j];
        if (i != 6) a = a * 10 + arr[0][i];
        res[a] = 1;
      }
    }
  }
  for (decltype(0) i = 0; i < 1000; i++) {
    if (res[i] == 0) {
      printf("%d", max(i - 1, 0));
      return 0;
    }
  }
}
