#include <bits/stdc++.h>
using namespace std;
int vis[10000];
int main() {
  int n;
  cin >> n;
  int a[3][10];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) cin >> a[i][j];
  }
  if (n == 1) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < 6; i++) {
      vis[a[0][i]] = 1;
    }
    int flag = 1;
    while (vis[flag]) flag++;
    cout << flag - 1 << endl;
  } else if (n == 2) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < 6; i++) {
      vis[a[0][i]] = 1;
    }
    for (int i = 0; i < 6; i++) {
      vis[a[1][i]] = 1;
    }
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) {
        vis[a[0][i] * 10 + a[1][j]] = 1;
        vis[a[1][i] * 10 + a[0][j]] = 1;
      }
    int flag1 = 1;
    while (vis[flag1]) flag1++;
    cout << flag1 - 1 << endl;
  } else {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < 6; i++) {
      vis[a[0][i]] = 1;
    }
    for (int i = 0; i < 6; i++) {
      vis[a[1][i]] = 1;
    }
    for (int i = 0; i < 6; i++) {
      vis[a[2][i]] = 1;
    }
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) {
        vis[a[0][i] * 10 + a[1][j]] = 1;
        vis[a[1][i] * 10 + a[0][j]] = 1;
      }
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) {
        vis[a[0][i] * 10 + a[2][j]] = 1;
        vis[a[2][i] * 10 + a[0][j]] = 1;
      }
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) {
        vis[a[1][i] * 10 + a[2][j]] = 1;
        vis[a[2][i] * 10 + a[1][j]] = 1;
      }
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++)
        for (int k = 0; k < 6; k++) {
          vis[a[0][i] * 100 + a[1][j] * 10 + a[2][k]] = 1;
          vis[a[0][i] * 100 + a[2][j] * 10 + a[1][k]] = 1;
          vis[a[1][i] * 100 + a[0][j] * 10 + a[2][k]] = 1;
          vis[a[1][i] * 100 + a[2][j] * 10 + a[0][k]] = 1;
          vis[a[2][i] * 100 + a[1][j] * 10 + a[0][k]] = 1;
          vis[a[2][i] * 100 + a[0][j] * 10 + a[1][k]] = 1;
        }
    int flag2 = 1;
    while (vis[flag2]) flag2++;
    cout << flag2 - 1 << endl;
  }
}
