public static void main ( String [ ] args ) {
  FastReader sc = new FastReader ( ) ;
  String s = sc . next ( ) ;
  int left = 0 ;
  int right = 0 ;
  int up = 0 ;
  int down = 0 ;
  for ( int i = 0 ;
  i < s . length ( ) ;
  i ++ ) {
    if ( s . charAt ( i ) == 'L' ) {
      left ++ ;
    }
    else if ( s . charAt ( i ) == 'R' ) {
      right ++ ;
    }
    else if ( s . charAt ( i ) == 'D' ) {
      down ++ ;
    }
    else {
      up ++ ;
    }
  }
  if ( s . length ( ) % 2 == 1 ) {
    System . out . println ( "-1" ) ;
  }
  else {
    int max1 = Math . max ( left , right ) ;
    int min1 = Math . min ( left , right ) ;
    int max2 = Math . max ( up , down ) ;
    int min2 = Math . min ( up , down ) ;
    int ans1 = max1 + max2 ;
    int ans2 = min1 + min2 ;
    System . out . println ( ( ans1 - ans2 ) / 2 ) ;
  }
}

public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; String s = sc . next ( ) ; int left = 0 ; int right = 0 ; int up = 0 ; int down = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' L ' ) { left ++ ; } else if ( s . charAt ( i ) == ' R ' ) { right ++ ; } else if ( s . charAt ( i ) == ' D ' ) { down ++ ; } else { up ++ ; } } if ( s . length ( ) % 2 == 1 ) { System . out . println ( " - 1" ) ; } else { int max1 = Math . max ( left , right ) ; int min1 = Math . min ( left , right ) ; int max2 = Math . max ( up , down ) ; int min2 = Math . min ( up , down ) ; int ans1 = max1 + max2 ; int ans2 = min1 + min2 ; System . out . println ( ( ans1 - ans2 ) / 2 ) ; } }
(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)))) (local_variable_declaration type: (type_identifier) 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: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (update_expression (identifier))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))))))))