import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int valleyCount = 0; int currentHeight = 0; boolean inValley = false; input.nextLine(); for (char step : input.next().toCharArray()) { currentHeight += step == 'U' ? 1 : -1; if (currentHeight < 0 && inValley == false) { valleyCount++; inValley = true; } if (inValley && currentHeight == 0) { inValley = false; } } System.out.println(valleyCount); } }