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. */ Scanner scan = new Scanner(System.in); int numSteps = Integer.parseInt(scan.nextLine()); String steps = scan.nextLine(); int numValleys = 0; int level = 0; boolean inValley = false; for (int i = 0; i < numSteps; i++) { if (steps.charAt(i) == 'U') { level += 1; } else level -= 1; if (level < 0 && !inValley) { inValley = true; } if (level == 0 && inValley) { inValley = false; numValleys += 1; } } System.out.println(numValleys); } }