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 sn = new Scanner(System.in); int numSteps = sn.nextInt(); if (numSteps < 2) { System.out.println("0"); } else { String s = sn.nextLine(); s = sn.nextLine(); char[] stepsArray = s.toCharArray(); boolean isInAValley = false; int countValleys = 0; int seaHeight = 0; for (int i = 0; i < stepsArray.length; i++) { if (stepsArray[i] == 'U') { seaHeight++; if (seaHeight == 0 && isInAValley) { countValleys++; isInAValley = false; } } else if (stepsArray[i] == 'D') { seaHeight--; if (seaHeight == -1) { isInAValley = true; } } } System.out.printf("%d",countValleys); } } }