public static void main ( String args [ ] ) throws IOException {
  Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ;
  PrintWriter pw = new PrintWriter ( System . out ) ;
  int n = sc . nextInt ( ) ;
  int m = sc . nextInt ( ) ;
  int arr [ ] = new int [ n + 1 ] ;
  ArrayList < Set < Integer >> dp = new ArrayList < > ( n + 1 ) ;
  dp . add ( new HashSet < Integer > ( ) ) ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) {
    dp . add ( new HashSet < Integer > ( ) ) ;
    arr [ i ] = sc . nextInt ( ) ;
  }
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    int a = sc . nextInt ( ) ;
    int b = sc . nextInt ( ) ;
    Set < Integer > c = dp . get ( b ) ;
    c . add ( a ) ;
    c = dp . get ( a ) ;
    c . add ( b ) ;
  }
  long min = 10000000000L ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) {
    Set < Integer > a = dp . get ( i ) ;
    for ( int b : a ) {
      Set < Integer > c = dp . get ( b ) ;
      for ( int d : c ) {
        if ( a . contains ( d ) ) {
          min = Math . min ( min , arr [ i ] + arr [ b ] + arr [ d ] ) ;
        }
      }
    }
  }
  if ( min == 10000000000L ) pw . println ( - 1 ) ;
  else pw . println ( min ) ;
  pw . close ( ) ;
}

public static void main ( String args [ ] ) throws IOException { Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int arr [ ] = new int [ n + 1 ] ; ArrayList < Set < Integer > > dp = new ArrayList < > ( n + 1 ) ; dp . add ( new HashSet < Integer > ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { dp . add ( new HashSet < Integer > ( ) ) ; arr [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Set < Integer > c = dp . get ( b ) ; c . add ( a ) ; c = dp . get ( a ) ; c . add ( b ) ; } long min = 10000000000L ; for ( int i = 1 ; i <= n ; i ++ ) { Set < Integer > a = dp . get ( i ) ; for ( int b : a ) { Set < Integer > c = dp . get ( b ) ; for ( int d : c ) { if ( a . contains ( d ) ) { min = Math . min ( min , arr [ i ] + arr [ b ] + arr [ d ] ) ; } } } } if ( min == 10000000000L ) pw . println ( - 1 ) ; else pw . println ( min ) ; pw . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) (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 (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: (integral_type) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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)))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (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 (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list))))) (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 (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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))) (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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (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 (identifier))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (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: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))