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 scanner = new Scanner(System.in); int num = scanner.nextInt(); int count = 0; boolean inValley = false; int numValleys = 0; String hike = scanner.next(); for (int i = 0; i < num; i++) { if (hike.charAt(i) == 'U') { count++; } else { count--; } if (count == 0 && inValley) { numValleys++; } inValley = count < 0; } System.out.println(numValleys); } }