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 lukija = new Scanner(System.in); int n = lukija.nextInt(); String stepSeq = lukija.next(); String[] steps = new String[n]; for (int step_i = 0; step_i < n; step_i++) { steps[step_i] = String.valueOf(stepSeq.charAt(step_i)); } boolean valley = false; int numberOfValleys = 0; int level = 0; for (int i = 0; i < steps.length; i++) { if (steps[i].equals("U")) { level++; if (valley && level >= 0) { valley = false; } } else { level--; if (!valley && level < 0) { valley = true; numberOfValleys++; } } } System.out.println(numberOfValleys); } }