import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int stepsNumber = sc.nextInt(); if (stepsNumber > 1000000 || stepsNumber < 2) { System.exit(0); } String pasosString = sc.next(); Character[] arraySteps = new Character[stepsNumber]; Integer[] arrayAltura = new Integer[stepsNumber]; int altura = 0; List arrayAlturaReal = new ArrayList(); for (int i = 0 ; i < stepsNumber ; i++){ arraySteps[i] = pasosString.charAt(i); if (arraySteps[i] == 'U'){ arrayAltura[i] = 1; altura += 1; arrayAlturaReal.add(altura); }else{ arrayAltura[i] = -1; altura -= 1; arrayAlturaReal.add(altura); } } int numeroValles = 0 ; for (int i = 0 ; i < stepsNumber ;i++){ if(arrayAlturaReal.get(i)== -1 ){ int j = i; try{ while( arrayAlturaReal.get(j) != 0 && j-1 < stepsNumber){ j++; } if (arrayAlturaReal.get(j) == 0){ numeroValles ++; i = j; } }catch(IndexOutOfBoundsException ex){ } } } System.out.println(numeroValles); } }