#include <bits/stdc++.h>
using namespace std;
int I1[6] = {-1, -1, -1, -1, -1, -1};
int I2[6] = {-1, -1, -1, -1, -1, -1};
int I3[6] = {-1, -1, -1, -1, -1, -1};
int main() {
  int n, br = 0, p = 0, x, y, g, z, b = 0;
  cin >> n;
  for (int i = 0; i < 6; i++) {
    cin >> g;
    I1[i] = g;
  }
  if (n >= 2)
    for (int i = 0; i < 6; i++) {
      cin >> g;
      I2[i] = g;
    }
  if (n >= 3)
    for (int i = 0; i < 6; i++) {
      cin >> g;
      I3[i] = g;
    }
  if (n == 1) {
    for (int i = 1; i <= 9; i++) {
      p = 0;
      for (int j = 0; j < 6; j++)
        if (i == I1[j]) p++;
      if (p == 0) {
        br = i - 1;
        break;
      }
    }
    cout << br;
  }
  if (n == 2) {
    for (int i = 1; i <= 9; i++) {
      p = 0;
      for (int j = 0; j < 6; j++)
        if (i == I1[j] || i == I2[j]) p++;
      if (p == 0) {
        br = i - 1;
        b++;
        break;
      }
    }
    if (b == 0)
      for (int i = 10; i <= 99; i++) {
        x = i / 10;
        y = i % 10;
        p = 0;
        for (int j = 0; j < 6; j++) {
          for (int k = 0; k < 6; k++)
            if (I2[j] == x && I1[k] == y || I2[j] == y && I1[k] == x) p++;
        }
        if (p == 0) {
          br = i - 1;
          break;
        }
      }
    cout << br;
  }
  if (n == 3) {
    for (int i = 1; i <= 9; i++) {
      p = 0;
      for (int j = 0; j < 6; j++)
        if (i == I1[j] || i == I2[j] || i == I3[j]) p++;
      if (p == 0) {
        br = i - 1;
        b++;
        break;
      }
    }
    if (b == 0)
      for (int i = 10; i <= 99; i++) {
        x = i / 10;
        y = i % 10;
        p = 0;
        for (int j = 0; j < 6; j++)
          for (int k = 0; k < 6; k++)
            if (I2[j] == x && I1[k] == y || I2[j] == y && I1[k] == x ||
                I3[j] == x && I1[k] == y || I3[j] == y && I1[k] == x ||
                I3[j] == x && I2[k] == y || I3[j] == y && I2[k] == x)
              p++;
        if (p == 0) {
          br = i - 1;
          b++;
          break;
        }
      }
    if (b == 0)
      for (int i = 100; i <= 500; i++) {
        x = i / 100;
        y = i / 10 % 10;
        z = i % 10;
        p = 0;
        for (int j = 0; j < 6; j++)
          for (int k = 0; k < 6; k++)
            for (int l = 0; l < 6; l++)
              if (I1[j] == x && I2[k] == y && I3[l] == z ||
                  I1[j] == x && I2[k] == z && I3[l] == y ||
                  I1[j] == y && I2[k] == x && I3[l] == z ||
                  I1[j] == y && I2[k] == z && I3[l] == x ||
                  I1[j] == z && I2[k] == x && I3[l] == y ||
                  I1[j] == z && I2[k] == y && I3[l] == x)
                if (p == 0) br = i - 1;
      }
    cout << br;
  }
}
