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 scan = new Scanner(System.in); int n = scan.nextInt(); String steps = scan.next(); //System.out.println(steps); calculateValleys(steps, n); } static void calculateValleys(String steps, int n) { int[] runningStepCount = new int[n+1]; runningStepCount[0] = 0; int tot = -9999; int sum = 0; int flag = 0; int count = 0; if (steps.charAt(0) == 'U') { sum = sum + 1; runningStepCount[1] = sum; } else { sum = sum - 1; runningStepCount[1] = sum; } if((runningStepCount[0] == 0) && (runningStepCount[1] == -1)) { tot = -1; flag = 1; } //System.out.println("0 ->" + runningStepCount[0]); //System.out.println("1 -> " + runningStepCount[1]); for(int i = 1; i < n; i++) { char step = steps.charAt(i); if(step == 'U') { sum = sum + 1; runningStepCount[i] = sum; if(flag == 1) tot = tot + 1; } else { sum = sum - 1; runningStepCount[i] = sum; if(flag == 1) tot = tot - 1; } //System.out.println(i + "->" + runningStepCount[i]); if((runningStepCount[i-1] == 0) && (runningStepCount[i] == -1)) { tot = -1; flag = 1; continue; } if(tot == 0) { count = count + 1; flag= 0; tot = -9999; } } System.out.println(count); } }