public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  int N = in . nextInt ( ) ;
  int [ ] [ ] cubes = new int [ N ] [ 6 ] ;
  for ( int cubeNo = 0 ;
  cubeNo < N ;
  cubeNo ++ ) {
    for ( int i = 0 ;
    i < 6 ;
    i ++ ) {
      cubes [ cubeNo ] [ i ] = in . nextInt ( ) ;
    }
  }
  Set < Integer > set = new HashSet < > ( ) ;
  for ( int cubeIdx1 = 0 ;
  cubeIdx1 < N ;
  cubeIdx1 ++ ) {
    for ( int sideIdx1 = 0 ;
    sideIdx1 < 6 ;
    sideIdx1 ++ ) {
      int side1 = cubes [ cubeIdx1 ] [ sideIdx1 ] ;
      set . add ( side1 ) ;
      for ( int cubeIdx2 = 0 ;
      cubeIdx2 < N ;
      cubeIdx2 ++ ) {
        if ( cubeIdx1 == cubeIdx2 ) {
          continue ;
        }
        for ( int sideIdx2 = 0 ;
        sideIdx2 < 6 ;
        sideIdx2 ++ ) {
          int side2 = cubes [ cubeIdx2 ] [ sideIdx2 ] ;
          set . add ( 10 * side1 + side2 ) ;
          set . add ( 10 * side2 + side1 ) ;
          for ( int cubeIdx3 = 0 ;
          cubeIdx3 < N ;
          cubeIdx3 ++ ) {
            if ( cubeIdx3 == cubeIdx1 || cubeIdx3 == cubeIdx2 ) {
              continue ;
            }
            for ( int sideIdx3 = 0 ;
            sideIdx3 < 6 ;
            sideIdx3 ++ ) {
              int side3 = cubes [ cubeIdx3 ] [ sideIdx3 ] ;
              set . add ( 100 * side1 + 10 * side2 + side3 ) ;
              set . add ( 100 * side1 + 10 * side3 + side2 ) ;
              set . add ( 100 * side2 + 10 * side1 + side3 ) ;
              set . add ( 100 * side2 + 10 * side3 + side1 ) ;
              set . add ( 100 * side3 + 10 * side1 + side2 ) ;
              set . add ( 100 * side3 + 10 * side2 + side1 ) ;
            }
          }
        }
      }
    }
  }
  int max = 1 ;
  while ( set . contains ( max ) ) {
    max ++ ;
  }
  System . out . println ( max - 1 ) ;
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int [ ] [ ] cubes = new int [ N ] [ 6 ] ; for ( int cubeNo = 0 ; cubeNo < N ; cubeNo ++ ) { for ( int i = 0 ; i < 6 ; i ++ ) { cubes [ cubeNo ] [ i ] = in . nextInt ( ) ; } } Set < Integer > set = new HashSet < > ( ) ; for ( int cubeIdx1 = 0 ; cubeIdx1 < N ; cubeIdx1 ++ ) { for ( int sideIdx1 = 0 ; sideIdx1 < 6 ; sideIdx1 ++ ) { int side1 = cubes [ cubeIdx1 ] [ sideIdx1 ] ; set . add ( side1 ) ; for ( int cubeIdx2 = 0 ; cubeIdx2 < N ; cubeIdx2 ++ ) { if ( cubeIdx1 == cubeIdx2 ) { continue ; } for ( int sideIdx2 = 0 ; sideIdx2 < 6 ; sideIdx2 ++ ) { int side2 = cubes [ cubeIdx2 ] [ sideIdx2 ] ; set . add ( 10 * side1 + side2 ) ; set . add ( 10 * side2 + side1 ) ; for ( int cubeIdx3 = 0 ; cubeIdx3 < N ; cubeIdx3 ++ ) { if ( cubeIdx3 == cubeIdx1 || cubeIdx3 == cubeIdx2 ) { continue ; } for ( int sideIdx3 = 0 ; sideIdx3 < 6 ; sideIdx3 ++ ) { int side3 = cubes [ cubeIdx3 ] [ sideIdx3 ] ; set . add ( 100 * side1 + 10 * side2 + side3 ) ; set . add ( 100 * side1 + 10 * side3 + side2 ) ; set . add ( 100 * side2 + 10 * side1 + side3 ) ; set . add ( 100 * side2 + 10 * side3 + side1 ) ; set . add ( 100 * side3 + 10 * side1 + side2 ) ; set . add ( 100 * side3 + 10 * side2 + side1 ) ; } } } } } } int max = 1 ; while ( set . contains ( max ) ) { max ++ ; } System . out . println ( max - 1 ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (decimal_integer_literal))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (continue_statement))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (identifier)))) consequence: (block (continue_statement))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (decimal_integer_literal) right: (identifier)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (identifier))))))))))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) body: (block (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))))