#include <bits/stdc++.h>
using namespace std;
int a[10], b[10], c[10], ou[1001];
int main() {
  int n, al;
  cin >> n;
  if (n == 1) {
    for (int i = 0; i < 6; i++) {
      cin >> al;
      ou[al]++;
    }
  }
  if (n == 2) {
    for (int i = 0; i < 6; i++) {
      cin >> al;
      a[i] = al;
      ou[al]++;
    }
    for (int i = 0; i < 6; i++) {
      cin >> al;
      b[i] = al;
      ou[al]++;
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        ou[a[i] * 10 + b[j]]++;
        ou[b[j] * 10 + a[i]]++;
      }
    }
  }
  if (n == 3) {
    for (int i = 0; i < 6; i++) {
      cin >> al;
      a[i] = al;
      ou[al]++;
    }
    for (int i = 0; i < 6; i++) {
      cin >> al;
      b[i] = al;
      ou[al]++;
    }
    for (int i = 0; i < 6; i++) {
      cin >> al;
      c[i] = al;
      ou[al]++;
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        ou[a[i] * 10 + b[j]]++;
        ou[b[j] * 10 + a[i]]++;
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        ou[b[i] * 10 + c[j]]++;
        ou[c[j] * 10 + b[i]]++;
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        ou[a[i] * 10 + c[j]]++;
        ou[c[j] * 10 + a[i]]++;
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        for (int k = 0; k < 6; k++) {
          ou[a[i] * 100 + b[j] * 10 + c[k]] = 1;
          ou[a[i] * 100 + c[k] * 10 + b[i]] = 1;
          ou[b[j] * 100 + a[i] * 10 + c[k]] = 1;
          ou[b[j] * 100 + c[k] * 10 + a[i]] = 1;
          ou[c[k] * 100 + a[i] * 10 + b[j]] = 1;
          ou[c[k] * 100 + b[j] * 10 + a[i]] = 1;
        }
      }
    }
  }
  for (int i = 1; i < 1001; i++) {
    if (ou[i] == 0) {
      cout << i - 1;
      return 0;
    }
  }
}
