import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int numSteps = scanner.nextInt(); scanner.nextLine(); String stepsStr = scanner.nextLine(); int[] steps = new int[numSteps]; int i = 0; for(char c : stepsStr.toCharArray()){ if(c == 'U' || c == 'u'){ steps[i++] = 1; }else if(c == 'D' || c == 'd'){ steps[i++] = -1; } } boolean isNegative = false; int valleyCount = 0; int sum = 0; for(i = 0; i < steps.length; ++i){ sum +=steps[i]; if(sum < 0){ isNegative = true; } if(sum == 0 && isNegative){ ++valleyCount; isNegative = false; } } System.out.println(valleyCount); } }