#include <bits/stdc++.h>
using namespace std;
int a[4][8];
priority_queue<int, vector<int>, greater<int> > pq;
set<int> s;
void i1c(int x) {
  for (int i = 1; i <= 6; i++) {
    if (a[x][i] != 0 && s.find(a[x][i]) == s.end()) {
      pq.push(a[x][i]);
    }
    s.insert(a[x][i]);
  }
}
void i2c(int x, int y) {
  for (int i = 1; i <= 6; i++) {
    if (a[x][i] == 0) continue;
    for (int j = 1; j <= 6; j++) {
      int tmp = a[x][i] * 10 + a[y][j];
      if (s.find(tmp) == s.end()) pq.push(tmp);
      s.insert(tmp);
    }
  }
}
void i3c(int x, int y, int z) {
  for (int i = 1; i <= 6; i++) {
    if (a[x][i] == 0) continue;
    for (int j = 1; j <= 6; j++)
      for (int k = 1; k <= 6; k++) {
        int tmp = a[x][i] * 100 + a[y][j] * 10 + a[z][k];
        if (s.find(tmp) == s.end()) pq.push(tmp);
        s.insert(tmp);
      }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pq.push((int)1e9);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 6; j++) {
      int x;
      cin >> x;
      a[i][j] = x;
    }
  if (n == 1) {
    i1c(1);
  } else if (n == 2) {
    i1c(1);
    i1c(2);
    i2c(1, 2);
    i2c(2, 1);
  } else {
    i1c(1);
    i1c(2);
    i1c(3);
    i2c(1, 2);
    i2c(2, 1);
    i2c(1, 3);
    i2c(3, 1);
    i2c(2, 3);
    i2c(3, 2);
    i3c(1, 2, 3);
    i3c(1, 3, 2);
    i3c(2, 1, 3);
    i3c(2, 3, 1);
    i3c(3, 1, 2);
    i3c(3, 2, 1);
  }
  for (int i = 1;; i++) {
    if (pq.top() != i) {
      cout << i - 1 << endl;
      break;
    }
    pq.pop();
  }
}
