import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] steps = new int[n]; char[] c = in.next().toCharArray(); int elevation = 0; int numValleys = 0; boolean isInValley = false; for(int i = 0; i < n; i++) { if(c[i] == 'U') steps[i] = 1; else steps[i] = -1; } for(int j = 0; j < n; j++) { elevation += steps[j]; if(elevation < 0 && !(isInValley)) { numValleys++; isInValley = true; } if(elevation >= 0) isInValley = false; } System.out.println(numValleys); } }