#include <bits/stdc++.h>
using namespace std;
int cube[4][10];
int main() {
  ios_base::sync_with_stdio(false);
  int n, temp;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 6; j++) {
      cin >> temp;
      cube[i][temp] = 1;
    }
  }
  bool tag = true;
  int a = 0, b = 0, c = 1;
  bool Q[3];
  while (tag) {
    tag = false;
    for (int i = 0; i < 3; i++) {
      if (a != 0) {
        for (int i = 0; i < 3; i++) {
          Q[0] = Q[1] = Q[2] = false;
          if (cube[i + 1][a] == 1) {
            Q[i] = true;
            for (int j = 0; j < 3; j++) {
              if (cube[j + 1][b] == 1 && Q[j] == false) {
                Q[j] = true;
                for (int k = 0; k < 3; k++) {
                  if (cube[k + 1][c] == 1 && Q[k] == false) {
                    tag = true;
                    Q[k] = true;
                    break;
                  }
                }
                if (tag == true) break;
              }
            }
          }
          if (tag == true) break;
        }
      } else if (b != 0) {
        for (int j = 0; j < 3; j++) {
          Q[0] = Q[1] = Q[2] = false;
          if (cube[j + 1][b] == 1 && Q[j] == false) {
            Q[j] = true;
            for (int k = 0; k < 3; k++) {
              if (cube[k + 1][c] == 1 && Q[k] == false) {
                tag = true;
                Q[k] = true;
                break;
              }
            }
            if (tag == true) break;
          }
        }
      } else {
        for (int k = 0; k < 3; k++) {
          Q[0] = Q[1] = Q[2] = false;
          if (cube[k + 1][c] == 1 && Q[k] == false) {
            tag = true;
            Q[k] = true;
            break;
          }
        }
      }
      if (tag == true) break;
    }
    c++;
    if (c == 10) {
      c = 0;
      b++;
      if (b == 10) {
        a++;
        b = 0;
        if (a == 10) {
          cout << "999";
          return 0;
        }
      }
    }
  }
  cout << a * 100 + b * 10 + c - 2 << endl;
}
