import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int level = 0; static String chart; static boolean ift; static int numval = 0; static int numLength; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); numLength = Integer.parseInt(scanner.nextLine()); chart = scanner.nextLine(); char dir; for(int i = 0; i < numLength; i++) { dir = chart.charAt(i); if(dir == 'D') level--; else level++; if(dir == 'D' && level == -1) { ift = true; } if(dir == 'U' && level == 0 && ift == true) { numval++; } } System.out.println(numval); } }