#include <bits/stdc++.h>
using namespace std;
int vis[4][20], a[4][20];
int tmp[1004];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 6; j++) {
      int x;
      cin >> x;
      a[i][j] = x;
      vis[i][x] = 1;
      tmp[x] = 1;
    }
  }
  for (int i = 1; i < n; i++) {
    for (int p = i + 1; p <= n; p++)
      for (int k = 1; k <= 6; k++)
        for (int j = 1; j <= 6; j++) {
          int tot = a[i][k] * 10 + a[p][j];
          tmp[tot] = 1;
          tot = a[p][j] * 10 + a[i][k];
          tmp[tot] = 1;
        }
  }
  for (int i = 1; i <= 1000; i++) {
    if (!tmp[i]) {
      cout << i - 1 << '\n';
      return 0;
    }
  }
}
