#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[3][6];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 2; i >= n; i--) {
    for (int j = 0; j < 6; j++) {
      a[i][j] = -1;
    }
  }
  int mas[3000];
  for (int i = 0; i < 3000; i++) {
    mas[i] = -1;
  }
  int ind = 0;
  for (int i = 0; i < 6; i++) {
    if (a[0][i] != -1) {
      mas[ind] = a[0][i];
      ind++;
    }
    if (a[1][i] != -1) {
      mas[ind] = a[1][i];
      ind++;
    }
    if (a[2][i] != -1) {
      mas[ind] = a[2][i];
      ind++;
    }
  }
  for (int i = 0; i < 6; i++) {
    for (int j = 0; j < 6; j++) {
      if (a[0][i] != -1 && a[1][j] != -1) {
        mas[ind] = 10 * a[0][i] + a[1][j];
        ind++;
      }
      if (a[0][i] != -1 && a[1][j] != -1) {
        mas[ind] = a[0][i] + 10 * a[1][j];
        ind++;
      }
      if (a[1][i] != -1 && a[2][j] != -1) {
        mas[ind] = 10 * a[1][i] + a[2][j];
        ind++;
      }
      if (a[1][i] != -1 && a[2][j] != -1) {
        mas[ind] = a[1][i] + 10 * a[2][j];
        ind++;
      }
      if (a[0][i] != -1 && a[2][j] != -1) {
        mas[ind] = 10 * a[0][i] + a[2][j];
        ind++;
      }
      if (a[0][i] != -1 && a[2][j] != -1) {
        mas[ind] = a[0][i] + 10 * a[2][j];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = 100 * a[0][i] + 10 * a[1][j] + a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = 100 * a[0][i] + a[1][j] + 10 * a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = 10 * a[0][i] + 100 * a[1][j] + a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = 10 * a[0][i] + a[1][j] + 100 * a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = a[0][i] + 10 * a[1][j] + 100 * a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 6; i++) {
    if (a[0][i] == -1) continue;
    for (int j = 0; j < 6; j++) {
      if (a[1][j] == -1) continue;
      for (int k = 0; k < 6; k++) {
        if (a[2][k] == -1) continue;
        mas[ind] = a[0][i] + 100 * a[1][j] + 10 * a[2][k];
        ind++;
      }
    }
  }
  for (int i = 0; i < 10; i++) {
  }
  for (int i = 1; i < 1000; i++) {
    bool bo = false;
    for (int j = 0; j <= ind; j++) {
      if (i == mas[j]) {
        bo = true;
        break;
      }
    }
    if (!bo) {
      break;
    } else
      ans = i;
  }
  cout << ans;
}
