import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static int getNumberOfSteps(String s) { return s.length(); } public static int getFinalHeight(String s) { int height = 0; for (int i = 0 ; i < s.length() ; i++) { if (s.charAt(i) == 'U') { height++; } else { height--; } } return height; } public static int getValleyCount(String s) { int valleyCount = 0; int height = 0; boolean inValley = false; for (int i = 0 ; i < s.length() ; i++) { if (s.charAt(i) == 'U') { height++; } else { height--; } if ((!inValley) && (height < 0)) { inValley = true; valleyCount++; } if (inValley && height >= 0) { inValley = false; } } return valleyCount; } public static void main(String[] args) { try (Scanner in = new Scanner(System.in);) { /* constraints: * * 2 <= n <= 1_000_000 */ int n = in.nextInt(); String s = in.next(); System.out.println(getValleyCount(s)); } } }