#include <bits/stdc++.h>
using namespace std;
int vis[3][10];
int N, M;
int main() {
  cin >> N;
  int x;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 6; j++) {
      cin >> x;
      vis[x][i] = true;
    }
  }
  for (int i = 1; i <= 999; i++) {
    int dig1 = i / 100;
    int dig2 = (i / 10) % 10;
    int dig3 = i % 10;
    if (dig1 != 0) {
      if (vis[dig1][0] && vis[dig2][1] && vis[dig3][2]) {
        continue;
      }
      if (vis[dig1][0] && vis[dig2][2] && vis[dig3][1]) {
        continue;
      }
      if (vis[dig1][1] && vis[dig2][0] && vis[dig3][2]) {
        continue;
      }
      if (vis[dig1][1] && vis[dig2][2] && vis[dig3][0]) {
        continue;
      }
      if (vis[dig1][2] && vis[dig2][1] && vis[dig3][0]) {
        continue;
      }
      if (vis[dig1][2] && vis[dig2][0] && vis[dig3][1]) {
        continue;
      }
    } else if (dig1 == 0 && dig2 != 0) {
      if (vis[dig2][0] && vis[dig3][1]) continue;
      if (vis[dig2][1] && vis[dig3][0]) continue;
      if (vis[dig2][2] && vis[dig3][1]) continue;
      if (vis[dig2][1] && vis[dig3][2]) continue;
      if (vis[dig2][0] && vis[dig3][2]) continue;
      if (vis[dig2][2] && vis[dig3][0]) continue;
    } else {
      if (vis[dig3][0] || vis[dig3][1] || vis[dig3][2]) continue;
    }
    cout << (i - 1) << endl;
    return (0);
  }
  cout << 999 << endl;
  return (0);
}
