public static void main ( String [ ] args ) throws Exception {
  BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  PrintWriter out = new PrintWriter ( System . out ) ;
  StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ;
  int n = Integer . parseInt ( st . nextToken ( ) ) ;
  int k = Integer . parseInt ( st . nextToken ( ) ) ;
  int [ ] a = new int [ k ] ;
  st = new StringTokenizer ( br . readLine ( ) ) ;
  for ( int i = 0 ;
  i < k ;
  i ++ ) a [ i ] = Integer . parseInt ( st . nextToken ( ) ) ;
  int fourSize = n , twoSize = 2 * n ;
  Arrays . sort ( a ) ;
  int one = 0 , two = 0 , three = 0 ;
  for ( int i = a . length - 1 ;
  i >= 0 ;
  i -- ) {
    if ( a [ i ] >= 4 ) {
      int countOfFours = a [ i ] / 4 ;
      int size = Math . min ( countOfFours , fourSize ) ;
      countOfFours -= size ;
      fourSize -= size ;
      if ( countOfFours > 0 ) {
        size = Math . min ( 2 * countOfFours , twoSize ) ;
        twoSize -= size ;
      }
      int rem = a [ i ] % 4 ;
      if ( rem == 1 ) one ++ ;
      else if ( rem == 2 ) {
        if ( twoSize > 0 ) twoSize -- ;
        else two ++ ;
      }
      else if ( rem == 3 ) three ++ ;
    }
    else if ( a [ i ] == 2 ) {
      if ( twoSize > 0 ) twoSize -- ;
      else two ++ ;
    }
    else if ( a [ i ] == 3 ) three ++ ;
    else one ++ ;
  };
}

public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int k = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] a = new int [ k ] ; st = new StringTokenizer ( br . readLine ( ) ) ; for ( int i = 0 ; i < k ; i ++ ) a [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; int fourSize = n , twoSize = 2 * n ; Arrays . sort ( a ) ; int one = 0 , two = 0 , three = 0 ; for ( int i = a . length - 1 ; i >= 0 ; i -- ) { if ( a [ i ] >= 4 ) { int countOfFours = a [ i ] / 4 ; int size = Math . min ( countOfFours , fourSize ) ; countOfFours -= size ; fourSize -= size ; if ( countOfFours > 0 ) { size = Math . min ( 2 * countOfFours , twoSize ) ; twoSize -= size ; } int rem = a [ i ] % 4 ; if ( rem == 1 ) one ++ ; else if ( rem == 2 ) { if ( twoSize > 0 ) twoSize -- ; else two ++ ; } else if ( rem == 3 ) three ++ ; } else if ( a [ i ] == 2 ) { if ( twoSize > 0 ) twoSize -- ; else two ++ ; } else if ( a [ i ] == 3 ) three ++ ; else one ++ ; } ; }
(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: (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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))))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) 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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (decimal_integer_literal) right: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (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: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (decimal_integer_literal) right: (identifier)) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier))) alternative: (expression_statement (update_expression (identifier))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier))) alternative: (expression_statement (update_expression (identifier))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier))) alternative: (expression_statement (update_expression (identifier))))))))))