public static void main ( String [ ] args ) throws IOException {
  BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  String [ ] str = br . readLine ( ) . split ( "" ) ;
  String [ ] s = br . readLine ( ) . split ( "" ) ;
  int [ ] arr = new int [ 10 ] ;
  int k = 0 ;
  HashMap < Integer , Integer > set = new HashMap < > ( ) ;
  for ( int i = 0 ;
  i < str . length ;
  i ++ ) {
    k = Integer . parseInt ( str [ i ] ) ;
    if ( k == 5 ) k = 2 ;
    if ( k == 9 ) k = 6 ;
    set . put ( k , set . getOrDefault ( k , 0 ) + 1 ) ;
  }
  for ( int j = 0 ;
  j < s . length ;
  j ++ ) {
    if ( s [ j ] . equals ( "5" ) || s [ j ] . equals ( "2" ) ) {
      arr [ 5 ] ++ ;
      arr [ 2 ] ++ ;
    }
    else if ( s [ j ] . equals ( "6" ) || s [ j ] . equals ( "9" ) ) {
      arr [ 6 ] ++ ;
      arr [ 9 ] ++ ;
    }
    else arr [ Integer . parseInt ( s [ j ] ) ] ++ ;
  }
  Set < Integer > map = set . keySet ( ) ;
  int min = Integer . MAX_VALUE ;
  for ( int a : map ) {
    min = Math . min ( min , arr [ a ] / set . get ( a ) ) ;
  }
  System . out . println ( min ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; String [ ] s = br . readLine ( ) . split ( " " ) ; int [ ] arr = new int [ 10 ] ; int k = 0 ; HashMap < Integer , Integer > set = new HashMap < > ( ) ; for ( int i = 0 ; i < str . length ; i ++ ) { k = Integer . parseInt ( str [ i ] ) ; if ( k == 5 ) k = 2 ; if ( k == 9 ) k = 6 ; set . put ( k , set . getOrDefault ( k , 0 ) + 1 ) ; } for ( int j = 0 ; j < s . length ; j ++ ) { if ( s [ j ] . equals ( "5" ) || s [ j ] . equals ( "2" ) ) { arr [ 5 ] ++ ; arr [ 2 ] ++ ; } else if ( s [ j ] . equals ( "6" ) || s [ j ] . equals ( "9" ) ) { arr [ 6 ] ++ ; arr [ 9 ] ++ ; } else arr [ Integer . parseInt ( s [ j ] ) ] ++ ; } Set < Integer > map = set . keySet ( ) ; int min = Integer . MAX_VALUE ; for ( int a : map ) { min = Math . min ( min , arr [ a ] / set . get ( a ) ) ; } System . out . println ( min ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))))) (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 (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal))) right: (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (string_literal))) right: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))) consequence: (block (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))) (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (string_literal))) right: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))) consequence: (block (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))) (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal))))) alternative: (expression_statement (update_expression (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))