#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int arr[10];
  int arr1[10];
  int arr2[10];
  while (cin >> n) {
    for (int i = 0; i <= 10; i++) {
      arr[i] = 0;
      arr1[i] = 0;
      arr2[i] = 0;
    }
    int x;
    for (int i = 1; i <= n; i++) {
      if (i == 1) {
        for (int j = 1; j <= 6; j++) {
          cin >> x;
          arr[x] = 1;
        }
      }
      if (i == 2) {
        for (int j = 1; j <= 6; j++) {
          cin >> x;
          arr1[x] = 1;
        }
      }
      if (i == 3) {
        for (int j = 1; j <= 6; j++) {
          cin >> x;
          arr2[x] = 1;
        }
      }
    }
    int ck = 0;
    for (int i = 1; i <= 9; i++) {
      if (arr[i] + arr1[i] + arr2[i] == 0) {
        cout << i - 1 << endl;
        ck = 1;
        break;
      }
    }
    int ck1 = 0;
    if (ck == 0) {
      for (int i = 10; i <= 99; i++) {
        ck1 = 0;
        int a = i;
        int x = a % 10;
        a /= 10;
        int y = a % 10;
        if ((arr[x] == 1 && (arr1[y] == 1 || arr2[y] == 1)) ||
            (arr[y] == 1 && (arr1[x] == 1 || arr2[x] == 1)))
          ck1 = 1;
        if ((arr1[x] == 1 && (arr[y] == 1 || arr2[y] == 1)) ||
            (arr1[y] == 1 && (arr[x] == 1 || arr2[x] == 1)))
          ck1 = 1;
        if ((arr2[x] == 1 && (arr[y] == 1 || arr1[y] == 1)) ||
            (arr2[y] == 1 && (arr1[x] == 1 || arr[x] == 1)))
          ck1 = 1;
        if (ck1 == 0) {
          cout << i - 1 << endl;
          break;
        }
      }
    }
  }
}
