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. */ try (Scanner scan = new Scanner(System.in)) { int n = scan.nextInt(); scan.nextLine(); String steps = scan.nextLine(); int level = 0; int count = 0; Character last = null; boolean valley = false; for (int i = 0; i < steps.length(); i ++) { char c = steps.charAt(i); if (c == 'U') { level ++; if (level == 0 && valley == true) { count ++; valley = false; } } else { if (level == 0) { valley = true; } level --; } last = c; } System.out.println(count); } } }