#include <bits/stdc++.h>
using namespace std;
int dices[4][6];
void solve() {
  int n;
  cin >> n;
  bool check[n][10];
  memset(check, false, sizeof(check));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      cin >> dices[i][j];
      check[i][dices[i][j]] = true;
    }
  }
  int f = 0;
  int ans = -1;
  for (int i = 1; i <= 9; i++) {
    int fl = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 6; k++) {
        if (dices[j][k] == i) {
          fl = 1;
          break;
        }
      }
      if (fl == 1) break;
    }
    if (fl == 0) {
      ans = i - 1;
      break;
    }
  }
  if (ans != -1) {
    cout << ans << '\n';
    return;
  }
  for (int i = 10; i <= 99; i++) {
    int k2 = i / 10;
    int k1 = i % 10;
    int fl = 0;
    for (int j = 0; j < n; j++) {
      int tr = 0;
      for (int k = 0; k < 6; k++) {
        if (dices[j][k] == k1) {
          tr++;
          break;
        }
      }
      if (tr == 1) {
        for (int k = 0; k < n; k++) {
          if (k != j) {
            for (int l = 0; l < 6; l++) {
              if (dices[k][l] == k2) {
                tr++;
                break;
              }
            }
          }
          if (tr == 2) break;
        }
      }
      if (tr == 2) {
        fl = 1;
        break;
      }
    }
    if (fl == 0) {
      ans = i - 1;
      break;
    }
  }
  if (ans != -1) {
    cout << ans << '\n';
    return;
  }
  for (int i = 100; i <= 999; i++) {
    int k3 = i / 100;
    int k1 = i % 10;
    int k2 = (i % 100) / 10;
    int fl = 0;
    if (check[0][k1] && check[1][k2] && check[2][k3]) {
      fl = 1;
    }
    if (check[0][k1] && check[1][k3] && check[2][k2]) {
      fl = 1;
    }
    if (check[0][k2] && check[1][k3] && check[2][k1]) {
      fl = 1;
    }
    if (check[0][k2] && check[1][k1] && check[2][k3]) {
      fl = 1;
    }
    if (check[0][k3] && check[1][k1] && check[2][k2]) {
      fl = 1;
    }
    if (check[0][k3] && check[1][k1] && check[2][k2]) {
      fl = 1;
    }
    if (fl != 1) {
      ans = i - 1;
      break;
    }
  }
  if (ans != -1) {
    cout << ans << '\n';
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
