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 totalSteps = in.nextInt(); String steps = in.next(); int sea_level = 0; int current = sea_level; int total_valleys = 0; boolean is_below_sea_level = false; for(int i = 0 ; i < totalSteps ; i++){ char step = steps.charAt(i); if (step == 'U') { current++; if(is_below_sea_level && current == sea_level){ total_valleys++; } } if (step == 'D') { current--; if(current < 0){ is_below_sea_level = true; } } } System.out.println(total_valleys); } }