import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int size = Integer.parseInt(br.readLine()); String steps = br.readLine(); int elevation = 0; boolean above = true; int vallies = 0; // loop through each step for(int i = 0; i < steps.length(); i++){ char step = steps.charAt(i); if(step == 'U'){ elevation++; } else{ elevation--; } if(above && elevation < 0){ // we were above, and went below vallies++; above = false; } else if(!above && elevation >= 0){ // we were below, and went above above = true; } } System.out.println(vallies); }catch(IOException io){ io.printStackTrace(); } } }