public static void main ( String [ ] args ) throws IOException {
  BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ;
  String s ;
  String sl [ ] ;
  int d [ ] = new int [ 10 ] ;
  int c [ ] = {
    999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 };
    for ( int i = 0 ;
    i <= 9 ;
    i ++ ) {
      d [ i ] = 999999 ;
    }
    s = r . readLine ( ) ;
    sl = s . split ( " " ) ;
    int n = Integer . parseInt ( sl [ 0 ] ) ;
    int m = Integer . parseInt ( sl [ 1 ] ) ;
    s = r . readLine ( ) ;
    sl = s . split ( " " ) ;
    for ( int i = 0 ;
    i < m ;
    i ++ ) {
      int v = Integer . parseInt ( sl [ i ] ) ;
      d [ v ] = c [ v ] ;
    }
    int dp [ ] = new int [ n + 1 ] ;
    for ( int i = 1 ;
    i <= n ;
    i ++ ) {
      dp [ i ] = - 999999 ;
      for ( int j = 1 ;
      j <= 9 ;
      j ++ ) {
        if ( i - d [ j ] >= 0 && dp [ i - d [ j ] ] >= 0 ) {
          dp [ i ] = Math . max ( dp [ i ] , dp [ i - d [ j ] ] + 1 ) ;
        }
      }
    }
    int z = dp [ n ] ;
    int q = n ;
    while ( q > 0 ) {
      for ( int i = 9 ;
      1 <= i ;
      i -- ) {
        if ( q - d [ i ] >= 0 && dp [ q - d [ i ] ] == dp [ q ] - 1 ) {
          System . out . print ( i ) ;
          q -= d [ i ] ;
          break ;
        }
      }
    }
  }
  
public static void main ( String [ ] args ) throws IOException { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ; String s ; String sl [ ] ; int d [ ] = new int [ 10 ] ; int c [ ] = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; for ( int i = 0 ; i <= 9 ; i ++ ) { d [ i ] = 999999 ; } s = r . readLine ( ) ; sl = s . split ( " ▁ " ) ; int n = Integer . parseInt ( sl [ 0 ] ) ; int m = Integer . parseInt ( sl [ 1 ] ) ; s = r . readLine ( ) ; sl = s . split ( " ▁ " ) ; for ( int i = 0 ; i < m ; i ++ ) { int v = Integer . parseInt ( sl [ i ] ) ; d [ v ] = c [ v ] ; } int dp [ ] = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { dp [ i ] = - 999999 ; for ( int j = 1 ; j <= 9 ; j ++ ) { if ( i - d [ j ] >= 0 && dp [ i - d [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - d [ j ] ] + 1 ) ; } } } int z = dp [ n ] ; int q = n ; while ( q > 0 ) { for ( int i = 9 ; 1 <= i ; i -- ) { if ( q - d [ i ] >= 0 && dp [ q - d [ i ] ] == dp [ q ] - 1 ) { System . out . print ( i ) ; q -= d [ i ] ; break ; } } } }
(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)))) (decimal_integer_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) dimensions: (dimensions))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (decimal_integer_literal) (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) 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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) right: (decimal_integer_literal)))))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (decimal_integer_literal) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (break_statement)))))))))