public static void main ( String ag [ ] ) {
  Scanner sc = new Scanner ( System . in ) ;
  int i , j , k ;
  int N = sc . nextInt ( ) ;
  int M = sc . nextInt ( ) ;
  HashSet < Integer > adj [ ] = new HashSet [ N + 1 ] ;
  for ( i = 0 ;
  i <= N ;
  i ++ ) adj [ i ] = new HashSet < > ( ) ;
  int degree [ ] = new int [ N + 1 ] ;
  for ( i = 1 ;
  i <= M ;
  i ++ ) {
    int a = sc . nextInt ( ) ;
    int b = sc . nextInt ( ) ;
    adj [ a ] . add ( b ) ;
    adj [ b ] . add ( a ) ;
    degree [ a ] ++ ;
    degree [ b ] ++ ;
  }
  int min = Integer . MAX_VALUE ;
  for ( i = 1 ;
  i <= N ;
  i ++ ) {
    int node1 = i ;
    Iterator < Integer > itr1 = adj [ node1 ] . iterator ( ) ;
    while ( itr1 . hasNext ( ) ) {
      int node2 = itr1 . next ( ) ;
      Iterator < Integer > itr2 = adj [ node2 ] . iterator ( ) ;
      while ( itr2 . hasNext ( ) ) {
        int node3 = itr2 . next ( ) ;
        if ( adj [ node3 ] . contains ( node1 ) ) min = Math . min ( min , degree [ node1 ] + degree [ node2 ] + degree [ node3 ] - 6 ) ;
      }
    }
  }
  System . out . println ( min == Integer . MAX_VALUE ? - 1 : min ) ;
}

public static void main ( String ag [ ] ) { Scanner sc = new Scanner ( System . in ) ; int i , j , k ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; HashSet < Integer > adj [ ] = new HashSet [ N + 1 ] ; for ( i = 0 ; i <= N ; i ++ ) adj [ i ] = new HashSet < > ( ) ; int degree [ ] = new int [ N + 1 ] ; for ( i = 1 ; i <= M ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; adj [ a ] . add ( b ) ; adj [ b ] . add ( a ) ; degree [ a ] ++ ; degree [ b ] ++ ; } int min = Integer . MAX_VALUE ; for ( i = 1 ; i <= N ; i ++ ) { int node1 = i ; Iterator < Integer > itr1 = adj [ node1 ] . iterator ( ) ; while ( itr1 . hasNext ( ) ) { int node2 = itr1 . next ( ) ; Iterator < Integer > itr2 = adj [ node2 ] . iterator ( ) ; while ( itr2 . hasNext ( ) ) { int node3 = itr2 . next ( ) ; if ( adj [ node3 ] . contains ( node1 ) ) min = Math . min ( min , degree [ node1 ] + degree [ node2 ] + degree [ node3 ] - 6 ) ; } } } System . out . println ( min == Integer . MAX_VALUE ? - 1 : min ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) 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)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (for_statement init: (assignment_expression left: (identifier) right: (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: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) 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)))))) (for_statement init: (assignment_expression left: (identifier) right: (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)))) (expression_statement (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (for_statement init: (assignment_expression left: (identifier) right: (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: (identifier))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (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))) right: (decimal_integer_literal))))))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (ternary_expression condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) consequence: (unary_expression operand: (decimal_integer_literal)) alternative: (identifier)))))))