import java.io.*; import java.util.*; 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. */ //input Scanner in = new Scanner(System.in); int numOfSteps = in.nextInt(); String steps = in.next(); int altitude = 0; boolean enterValley = false; int numValleys = 0; for(int i = 0; i < numOfSteps; i++) { char c = steps.charAt(i); if (c == 'U') { altitude += 1; } else if (c == 'D') { altitude -= 1; } if (altitude < 0) { enterValley = true; } if ((altitude == 0) && enterValley) { numValleys++; enterValley = false; } } System.out.print(numValleys); } }