#include <bits/stdc++.h>
using namespace std;
bool a[3][10];
int n, curr;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      int b;
      cin >> b;
      a[i][b] = true;
    }
  }
  for (int digit = 0; digit <= 9; digit++) {
    for (int i = 0; i < n; i++) {
      if (a[i][digit]) curr = digit;
    }
    if (curr < digit) {
      cout << curr;
      return 0;
    }
  }
  if (n < 2) {
    cout << curr;
    return 0;
  }
  for (int digit = 10; digit <= 99; digit++) {
    int d1 = digit / 10, d2 = digit % 10;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (a[i][d1] && a[j][d2] && i != j) curr = digit;
      }
    }
    if (curr < digit) {
      cout << curr;
      return 0;
    }
  }
  if (n < 3) {
    cout << curr;
    return 0;
  }
  for (int digit = 100; digit <= 999; digit++) {
    int d1 = digit / 100, d2 = digit / 10 % 10, d3 = digit % 10;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (a[i][d1] && a[j][d2] && a[k][d3] && i != j && i != k && j != k)
            curr = digit;
        }
      }
    }
    if (curr < digit) {
      cout << curr;
      return 0;
    }
  }
}
