#include <bits/stdc++.h>
using namespace std;
int vis[100000];
int main() {
  int n, v;
  cin >> n;
  int a[4][10];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) {
      cin >> a[i][j];
      vis[a[i][j]] = 1;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 6; j++) {
      for (int k = i + 1; k <= n; k++) {
        for (int l = 1; l <= 6; l++) {
          vis[a[i][j] * 10 + a[k][l]] = 1;
          vis[a[k][l] * 10 + a[i][j]] = 1;
        }
      }
    }
  }
  if (n == 3)
    for (int i = 1; i <= 6; i++) {
      for (int j = 1; j <= 6; j++) {
        for (int k = 1; k <= 6; k++) {
          vis[a[1][i] * 100 + a[2][j] * 10 + a[3][k]] = 1;
          vis[a[1][i] * 100 + a[3][k] * 10 + a[2][j]] = 1;
          vis[a[2][j] * 100 + a[1][i] * 10 + a[3][k]] = 1;
          vis[a[2][j] * 100 + a[3][k] * 10 + a[1][i]] = 1;
          vis[a[3][k] * 100 + a[2][j] * 10 + a[1][i]] = 1;
          vis[a[3][k] * 100 + a[1][i] * 10 + a[2][j]] = 1;
        }
      }
    }
  int ans = 0;
  vis[0] = 1;
  while (vis[ans]) ans++;
  cout << ans - 1;
  return 0;
}
