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 in = new Scanner(System.in); int n = in.nextInt(); String input = in.nextLine(); input = in.nextLine(); boolean sealevel = true; int stepup =0, stepdown = 0, mountain =0, valley =0; boolean aboveSeaLevel=false, belowSeaLevel=false; for (char ch: input.toCharArray()) { if(ch == 'U'){ stepup++; if (sealevel){ sealevel=false; aboveSeaLevel = true; } } if (ch == 'D'){ stepdown++; if (sealevel){ sealevel=false; belowSeaLevel = true; } } if(stepdown==stepup){ if(belowSeaLevel) {valley++;} if(aboveSeaLevel) {mountain++;} stepup =0; stepdown = 0; sealevel=true; belowSeaLevel = false; aboveSeaLevel = false; } //System.out.println(ch+" U "+stepup+" D "+stepdown +"Valley "+valley+" Mountain "+mountain+ "abovesea "+aboveSeaLevel+" belowsea"+belowSeaLevel ); } System.out.println(valley); // System.out.println(mountain); } }