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) { Scanner input = new Scanner(System.in); int n = input.nextInt(); String stepPattern = input.next(); int[] altitude = new int[n+1]; int currentAlt = 0; altitude[0] = currentAlt; for (int i = 0; i < n; i++){ if (stepPattern.charAt(i) == 'U'){ currentAlt++; } else{ currentAlt--; } altitude[i+1] = currentAlt; } int valley = 0; for (int k = 1; k < altitude.length; k++){ if (altitude[k] == 0 && altitude[k-1] < 0){ valley++; } } System.out.println(valley); } }