public static void main ( String args [ ] ) {
  FastScanner f = new FastScanner ( ) ;
  int n = f . nextInt ( ) ;
  String str = f . next ( ) ;
  int x = 0 , y = 0 ;
  int count = 0 ;
  int prevX , prevY ;
  for ( int i = 0 ;
  i < str . length ( ) ;
  i ++ ) {
    prevX = x ;
    prevY = y ;
    if ( str . charAt ( i ) == 'U' ) {
      y ++ ;
    }
    else {
      x ++ ;
    }
    if ( x == y && i + 1 < str . length ( ) ) {
      char next = str . charAt ( i + 1 ) ;
      int nextX = x , nextY = y ;
      if ( next == 'U' ) {
        nextY ++ ;
      }
      else {
        nextX ++ ;
      }
      if ( ( prevX == x - 1 && nextX == x + 1 ) || ( prevY == y - 1 && nextY == y + 1 ) ) {
        count ++ ;
      }
    }
  }
  System . out . println ( count ) ;
}

public static void main ( String args [ ] ) { FastScanner f = new FastScanner ( ) ; int n = f . nextInt ( ) ; String str = f . next ( ) ; int x = 0 , y = 0 ; int count = 0 ; int prevX , prevY ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { prevX = x ; prevY = y ; if ( str . charAt ( i ) == ' U ' ) { y ++ ; } else { x ++ ; } if ( x == y && i + 1 < str . length ( ) ) { char next = str . charAt ( i + 1 ) ; int nextX = x , nextY = y ; if ( next == ' U ' ) { nextY ++ ; } else { nextX ++ ; } if ( ( prevX == x - 1 && nextX == x + 1 ) || ( prevY == y - 1 && nextY == y + 1 ) ) { count ++ ; } } } System . out . println ( count ) ; }
(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)))) (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: (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)) 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)) declarator: (variable_declarator name: (identifier))) (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 (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (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: (identifier) right: (identifier)) right: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier)) declarator: (variable_declarator name: (identifier) value: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (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: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))))) consequence: (block (expression_statement (update_expression (identifier))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))