import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numberSteps = sc.nextInt(); int valleyCount = 0; int seaLevel = 0; String steps = sc.next(); boolean bellow = false; for ( int i = 0; i < numberSteps; i++ ) { seaLevel += steps.charAt(i) == 'U' ? 1 : (-1); if (seaLevel < 0 && !bellow) { valleyCount++; bellow = true; } else if (seaLevel >= 0 && bellow) bellow = false; } System.out.println(valleyCount); } }