import java.util.Scanner;

public class CountingValleys {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        sc.nextLine();
        String steps = sc.nextLine();
        int seaLevel = 0, valley = 0;
        boolean inValley = false;
        for(int i = 0; i < steps.length(); i ++){
            if(steps.charAt(i) == 'U')
                seaLevel++;
            else
                seaLevel--;
            if(inValley == true && seaLevel == 0)
                valley++;
            if(seaLevel < 0)
                inValley = true;
            else
                inValley = false;
        }
        System.out.println(valley);
        sc.close();
    }
}