#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int s[3][6];
  int answer = 0;
  vector<int> allNums;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 6; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  if (n == 1) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        allNums.push_back(s[i][j]);
      }
    }
  } else if (n == 2) {
    for (int j = 0; j < 6; j++) {
      allNums.push_back(s[0][j]);
    }
    for (int j = 0; j < 6; j++) {
      allNums.push_back(s[1][j]);
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        allNums.push_back(s[0][i] * 10 + s[1][j]);
        allNums.push_back(s[0][i] + s[1][j] * 10);
      }
    }
  } else {
    for (int j = 0; j < 6; j++) {
      allNums.push_back(s[0][j]);
    }
    for (int j = 0; j < 6; j++) {
      allNums.push_back(s[1][j]);
    }
    for (int j = 0; j < 6; j++) {
      allNums.push_back(s[2][j]);
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        allNums.push_back(s[0][i] * 10 + s[1][j]);
        allNums.push_back(s[0][i] + s[1][j] * 10);
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        allNums.push_back(s[0][i] * 10 + s[2][j]);
        allNums.push_back(s[0][i] + s[2][j] * 10);
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        allNums.push_back(s[2][i] * 10 + s[1][j]);
        allNums.push_back(s[2][i] + s[1][j] * 10);
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        for (int k = 0; k < 6; k++) {
          allNums.push_back(s[0][i] * 100 + s[1][j] * 10 + s[2][k]);
          allNums.push_back(s[0][i] * 100 + s[2][j] * 10 + s[1][k]);
          allNums.push_back(s[1][i] * 100 + s[0][j] * 10 + s[2][k]);
          allNums.push_back(s[1][i] * 100 + s[2][j] * 10 + s[0][k]);
          allNums.push_back(s[2][i] * 100 + s[1][j] * 10 + s[0][k]);
          allNums.push_back(s[2][i] * 100 + s[0][j] * 10 + s[1][k]);
        }
      }
    }
  }
  for (int i = 1; i < 999; i++) {
    bool found = false;
    for (int j = 0; j < allNums.size(); j++) {
      if (i == allNums[j]) {
        found = true;
      }
    }
    if (found == false) {
      answer = i - 1;
      break;
    }
  }
  printf("%d\n", answer);
  return 0;
}
