public static void main ( String [ ] args ) {
  Scanner scan = new Scanner ( System . in ) ;
  int clothes = scan . nextInt ( ) , num = scan . nextInt ( ) , a , b , help , min = 3000000 ;
  int [ ] price = new int [ clothes + 1 ] ;
  boolean match = false ;
  boolean [ ] [ ] graph = new boolean [ 101 ] [ 101 ] ;
  for ( int i = 1 ;
  i <= clothes ;
  i ++ ) price [ i ] = scan . nextInt ( ) ;
  for ( int i = 0 ;
  i < num ;
  i ++ ) {
    a = scan . nextInt ( ) ;
    b = scan . nextInt ( ) ;
    graph [ a ] [ 0 ] = true ;
    graph [ b ] [ 0 ] = true ;
    graph [ a ] [ b ] = true ;
    graph [ b ] [ a ] = true ;
  }
  for ( int i = 1 ;
  i <= clothes ;
  i ++ ) for ( int j = 1 ;
  j <= clothes && graph [ i ] [ 0 ] ;
  j ++ ) if ( graph [ i ] [ j ] ) for ( int k = 1 ;
  k <= clothes && graph [ j ] [ 0 ] ;
  k ++ ) if ( graph [ j ] [ k ] && graph [ i ] [ k ] ) {
    match = true ;
    help = price [ i ] + price [ j ] + price [ k ] ;
    if ( min > help ) min = help ;
  }
  System . out . println ( ! match ? - 1 : min ) ;
}

public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int clothes = scan . nextInt ( ) , num = scan . nextInt ( ) , a , b , help , min = 3000000 ; int [ ] price = new int [ clothes + 1 ] ; boolean match = false ; boolean [ ] [ ] graph = new boolean [ 101 ] [ 101 ] ; for ( int i = 1 ; i <= clothes ; i ++ ) price [ i ] = scan . nextInt ( ) ; for ( int i = 0 ; i < num ; i ++ ) { a = scan . nextInt ( ) ; b = scan . nextInt ( ) ; graph [ a ] [ 0 ] = true ; graph [ b ] [ 0 ] = true ; graph [ a ] [ b ] = true ; graph [ b ] [ a ] = true ; } for ( int i = 1 ; i <= clothes ; i ++ ) for ( int j = 1 ; j <= clothes && graph [ i ] [ 0 ] ; j ++ ) if ( graph [ i ] [ j ] ) for ( int k = 1 ; k <= clothes && graph [ j ] [ 0 ] ; k ++ ) if ( graph [ j ] [ k ] && graph [ i ] [ k ] ) { match = true ; help = price [ i ] + price [ j ] + price [ k ] ; if ( min > help ) min = help ; } System . out . println ( ! match ? - 1 : min ) ; }
(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))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_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 (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (decimal_integer_literal)) 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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (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: (block (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)))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (true))))) (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: (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))) update: (update_expression (identifier)) body: (if_statement condition: (parenthesized_expression (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))) consequence: (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))) update: (update_expression (identifier)) body: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))) right: (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (ternary_expression condition: (unary_expression operand: (identifier)) consequence: (unary_expression operand: (decimal_integer_literal)) alternative: (identifier)))))))