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