#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int grid[n][6];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) cin >> grid[i][j];
  }
  int hash[1000] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      hash[grid[i][j]]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      for (int k = i + 1; k < n; k++) {
        for (int l = 0; l < 6; l++) {
          hash[(grid[i][j] * 10 + grid[k][l])]++;
          hash[(grid[k][l] * 10 + grid[i][j])]++;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      for (int k = i + 1; k < n; k++) {
        for (int l = 0; l < 6; l++) {
          for (int m = k + 1; m < n; m++) {
            for (int h = 0; h < 6; h++) {
              hash[(grid[i][j] * 100 + grid[k][l] * 10 + grid[m][h])]++;
              hash[(grid[i][j] * 100 + grid[m][h] * 10 + grid[k][l])]++;
              hash[(grid[k][l] * 100 + grid[i][j] * 10 + grid[m][h])]++;
              hash[(grid[k][l] * 100 + grid[m][h] * 10 + grid[i][j])]++;
              hash[(grid[m][h] * 100 + grid[i][j] * 10 + grid[k][l])]++;
              hash[(grid[m][h] * 100 + grid[k][l] * 10 + grid[i][j])]++;
            }
          }
        }
      }
    }
  }
  for (int i = 1; i < 1000; i++) {
    if (hash[i] == 0) {
      cout << (i - 1);
      break;
    }
  }
}
