#include <bits/stdc++.h>
using namespace std;
int n, arr[4][10];
bool vis[1100];
void dfs(int r, int c, int num, int cnt) {
  if (cnt == n) {
    return;
  }
  for (int i = 1; i <= n; ++i) {
    if (i != r) {
      for (int j = 1; j <= 6; ++j) {
        vis[num + arr[i][j] * (int)pow(10, cnt)] = true;
        dfs(i, j, num + arr[i][j] * (int)pow(10, cnt), cnt + 1);
      }
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= 6; ++j) {
      cin >> arr[i][j];
    }
  }
  dfs(0, 0, 0, 0);
  for (int i = 1; i <= 1100; ++i) {
    if (vis[i] == false) {
      cout << i - 1;
      break;
    }
  }
}
