import java.io.*; import java.util.*; 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 scan = new Scanner(System.in); int numLetters = Integer.parseInt(scan.nextLine()); String letters = scan.nextLine(); int sum = 0; boolean valleyStarted = false; int count = 0; for (int i = 0; i < numLetters; i++){ char c = letters.charAt(i); if (c == 'U'){ sum++; }else if (c == 'D'){ sum--; } if (!valleyStarted && sum < 0){ valleyStarted = true; } if (valleyStarted && sum == 0){ count++; valleyStarted = false; } } System.out.println(count); } }